or
[TestMethod]
public
void
JustMockTest_String_Arrays()
{
// Arrange
Mock.SetupStatic(
typeof
(System.IO.File));
string
[] sourceFiles =
new
string
[] { @
"X:\source\file1.txt"
};
string
[] destinationFiles =
new
string
[] { @
"X:\destination\file1.txt"
};
// Act
System.IO.File.Copy(sourceFiles[0], destinationFiles[0]);
// Assert
Mock.Assert(() => System.IO.File.Copy(sourceFiles[0], destinationFiles[0]), Occurs.Once());
}
[TestMethod]
public
void
JustMockTest_String_Arrays_ToString()
{
// Arrange
Mock.SetupStatic(
typeof
(System.IO.File));
string
[] sourceFiles =
new
string
[] { @
"X:\source\file1.txt"
};
string
[] destinationFiles =
new
string
[] { @
"X:\destination\file1.txt"
};
// Act
System.IO.File.Copy(sourceFiles[0], destinationFiles[0]);
// Assert
Mock.Assert(() => System.IO.File.Copy(sourceFiles[0].ToString(), destinationFiles[0].ToString()), Occurs.Once());
}
var Dte = Mock.Create<
DTE
>();
var activeProject = Mock.Create<
Project
>();
var solution = Mock.Create<
Solution
>();
Mock.SetupStatic(typeof(RazorTemplateExtensions));
Mock.Arrange(() => Dte.Solution).Returns(solution);
Mock.Arrange(() => RazorTemplateExtensions.Dte).Returns(Dte);
Mock.Arrange(() => Solution.FileName).Returns("SolutionNameTest");
Mock.Arrange(() => ActiveProject.RootNamespace()).Returns("DefaultNamespace");
Mock.Arrange(() => Solution.ActiveProject()).Returns(ActiveProject);
public static String DirectoryPath(this RazorTemplate razorTemplate)
{
var solution = Dte.Solution;
// while breaking here this solution is null
// In the immediate window the Dte.Solution returns proxy object.
...
}
[TestMethod]
public
void
MyClass_GetInt_with_MustBeCalled()
{
// Arrange
var myClass = Mock.Create<MyClass>();
Mock.Arrange(() => myClass.GetInt())
.Returns(911)
.MustBeCalled();
// Act
int
result = myClass.GetInt();
// Assert
Assert.AreEqual(911, result);
Mock.Assert(myClass);
}
[TestMethod]
public
void
MyClass_GetInt_with_OccursNever()
{
// Arrange
var myClass = Mock.Create<MyClass>();
Mock.Arrange(() => myClass.GetInt())
.Returns(911)
.OccursNever();
// Act
int
result = myClass.GetInt();
// Assert
Assert.AreEqual(911, result);
Mock.Assert(myClass);
}
[TestMethod]
public
void
EntityTest()
{
// Arrange
var siteFeatures =
new
List<SiteFeature>();
var entities = Mock.Create<MyEntities>();
Mock.Arrange(() => entities.SiteFeatures)
.ReturnsCollection(siteFeatures)
.MustBeCalled();
// Act
var exists = entities.SiteFeatures.FirstOrDefault(s => s.SiteId == 123) !=
null
;
// Assert
Assert.IsFalse(exists);
}
SPContentType mockedContentType = Mock.Create<SPContentType>();
Initialization method X.KeywordFinderTests.Initialize threw exception. System.MissingMethodException: System.MissingMethodException: Constructor on type
'Microsoft.SharePoint.SPContentType'
not found..
SPContentType mockedContentType = Mock.Create<SPContentType>(SPContentTypeId.Empty);
SPContentType mockedContentType = Mock.Create<SPContentType>(
new
SPContentTypeId(
"0x01")
);
SPContentType mockedContentType = Mock.Create<SPContentType>(Constructor.Mocked);
SPContentType mockedContentType =
new
SPContentType(
new
ContentTypeId(
"0x01"
), mockedContentTypeCollection,
"My Content Type"
);
Initialization method X.KeywordFinderTests.Initialize threw exception. System.NullReferenceException: System.NullReferenceException: Object reference not
set
to an instance of an
object
..