Skip to content

Instantly share code, notes, and snippets.

View Get_Person_By_Id
[Fact]
public void Get_Person_By_Id()
{
var person = new Person { BusinessEntityID = 3};
var mockpersonRepository = new Mock();
mockpersonRepository.Setup(x => x.GetPersonById(3))
.Returns(person); //return Person
mockpersonRepository.Object.GetPersonById(3).ShouldBe(person); //Assert expected value equal to actual value
mockpersonRepository.Verify(x => x.GetPersonById(person.BusinessEntityID), Times.Once()); //Assert that the Get method was called once
View PersonRepository.cs
public class PersonRepository : GenericRepository<Person>, IPersonRepository
{
public PersonRepository(IUnitOfWork uow) : base(uow)
{
}
public Person GetPersonById(long id)
{
return GetById(id);
}
View Create_Person_Calls_PersonRepositoryAdd
[Fact]
public void Create_Person_Calls_PersonRepositoryAdd()
{
var person = new Person { BusinessEntityID = 3};
var mockpersonRepository = new Mock<IPersonRepository>();
mockpersonRepository.Setup(x => x.Add(person)); //no return as it's a void method
mockpersonRepository.Object.Add(person);
mockpersonRepository.Verify(x => x.Add(person), Times.Once()); //Assert that the Add method was called once
View Delete_Person_ById
[Fact]
public void Delete_Person_ById()
{
var person = new Person {BusinessEntityID = 3};
var mockpersonRepository = new Mock();
mockpersonRepository.Setup(x => x.Delete(person));
mockpersonRepository.Object.Delete(person); //no return as it's a void method
View testapp.js
var app = angular.module('testApp',[]).directive('myDirective1',function(){
return{
template:"<div>Hello from directive 1</div>",
replace:true,
retrict:'E'
}
}).directive('myDirective2',function(){
return{
template:"<div>Hello from directive 2</div>",
replace:true,
View test.html
<!DOCTYPE html>
<html ng-app="testApp" ng-strict-di>
<head>
<base ref="/">
<meta content="IE=edge, chrome=1" http-equiv="X-UA-Compatible" />
<body ng-controller="HomeController as AppCtrl">
<my-directive1></my-directive1>
<my-directive2></my-directive2>
You can’t perform that action at this time.