public void DeleteOperationTest() { Mock<IOperationRepository> mock = new Mock<IOperationRepository>(); Mock<IUserRepository> mockUser = CreateUserRepository(); PurseController controller = new PurseController(mock.Object, mockUser.Object); controller.DeleteOperation(2); mock.Verify(m => m.RemoveOperation(It.IsAny<int>(), It.IsAny<int>())); }
public void IfNotReportsThenThrowException() { var builder = new Mock<IReportBuilder>(); builder.Setup(m => m.CreateReports()).Returns(new List<Report>()); var sender = new Mock<IReportSender>(); var reporter = new Reporter(builder.Object, sender.Object); Assert.Throws<NoReportsException>(() => reporter.SendReports()); }
public void AMessageIsSentToTheCustomerWhoWasAddedToTheBankImplementeWithMock() { string expectedRecipient = "*****@*****.**"; string expectedContent = "Dear Andy, welcome to the bank."; var mockGateway = new Mock<MessageGateway>(); mockGateway.Setup(x => x.Send(expectedRecipient, expectedContent)); var bank = new Bank(new EmptyNicknameValidator(), new DuplicatedNicknameValidator(), mockGateway.Object); var customer = bank.AddCustomer("Andy", new DateTime(1981, 1, 1), "*****@*****.**"); mockGateway.VerifyAll(); }
public void TestMethod1() { var test = new Mock<TestClass> { CallBase = true }; test.Setup(t => t.NormalMethod()).Returns("Mock"); test.Setup(t => t.VirtualMethod()).Returns("Mock"); test.Setup(t => t.SealedMethod()).Returns("Mock"); test.Setup(t => t.AbstractMethod()).Returns("Mock"); test.Protected().Setup<string>("PrivateMethod").Returns("Mock"); Assert.AreEqual(test.Object.NormalMethod(), "Mock"); Assert.AreEqual(test.Object.VirtualMethod(), "Mock"); Assert.AreEqual(test.Object.SealedMethod(), "Mock"); Assert.AreEqual(test.Object.AbstractMethod(), "Mock"); Assert.AreEqual(test.Object.CallPrivateMethod(), "Mock"); }
public void Can_Pignate() { Mock<IProductRepository> repository = new Mock<IProductRepository>(); repository.Setup(m => m.Products).Returns(new Product[]{ new Product{ProductId=1,Name="1",Description="1"}, new Product{ProductId=2,Name="2",Description="2"} , new Product{ProductId=3,Name="3",Description="3"}, new Product{ProductId=4,Name="4",Description="4"}, new Product{ProductId=5,Name="5",Description="5"} }.AsQueryable()); ProductController controller = new ProductController(repository.Object); controller.PageSize = 4; IEnumerable<Product> result = (IEnumerable<Product>)controller.List(2).Model; Assert.IsTrue(result.Count() == 1); Product[]prod= result.ToArray(); Assert.AreEqual(prod[0].Name, "5"); }
public void Put_Person_Throws_When_Update_fails() { // Arrange var person = new Web.Models.Person {Id = ObjectId.GenerateNewId().ToString()}; var service = new Mock<IPersonService>(); service.Setup(s => s.Update(It.IsAny<Library.Entity.Person>())).Throws<Exception>(); var controller = new PersonController(service.Object); // Act var result = controller.Put(person.Id, person) as ExceptionResult; // Assert Assert.NotNull(result); }
public void Get_Person_Throws_when_service_returns_null() { // Arrange var id = new ObjectId().ToString(); var service = new Mock<IPersonService>(); service.Setup(s => s.Get(id)).Returns((Library.Entity.Person) null);// Had trouble making the static setup work like in the other tests var controller = new PersonController(service.Object); // Act var result = controller.Get(id); // Assert Assert.IsType<NotFoundResult>(result); }
private Mock<IUserRepository> CreateUserRepository() { Mock<IUserRepository> mock = new Mock<IUserRepository>(); mock.Setup(x => x.GetUserID(null)).Returns(1); mock.Setup(x => x.GetUserName(It.IsAny<int>())).Returns("akorop"); return mock; }
private Mock<IOperationRepository> CreateRepository() { Mock<IOperationRepository> mock = new Mock<IOperationRepository>(); var model = new PreviewModel(); model.AddDaySpanOperation(2012,1,1,new SingleOperation{Id = 0,OperationName = "Novus", Value = 40}); model.AddDaySpanOperation(2012,1,1,new SingleOperation{Id = 1,OperationName = "MacDonalds", Value = 40}); model.AddDaySpanOperation(2012,1,5,new SingleOperation{Id = 2,OperationName = "Mouse", Value = 40}); model.AddDaySpanOperation(2012, 2, 1, new SingleOperation { Id = 3, OperationName = "MacDonalds", Value = 40 }); model.AddDaySpanOperation(2012, 2, 5, new SingleOperation { Id = 4, OperationName = "Mouse", Value = 40 }); model.SetCurrentMonth(1, 2012); mock.Setup(x => x.Model(It.IsAny<int>())).Returns(model); return mock; }