public void Add_ShouldThrowArgumentNullException_WhenEntityIsNullable() { var mockDbSet = new Mock <DbSet <FakeEmployee> >(); var mockDbContext = new Mock <ISalaryCalculatorDbContext>(); mockDbContext.Setup(mock => mock.Set <FakeEmployee>()).Returns(mockDbSet.Object); var repo = new SalaryCalculatorRepository <FakeEmployee>(mockDbContext.Object); Assert.That(() => repo.Add(null), Throws.InstanceOf <ArgumentNullException>().With.Message.Contains("Entity cannot be null")); }
public void AddMethod_ShouldInvokedOnce_WhenParameterIsPassedCorrectly() { var fakeDbSet = new Mock <DbSet <FakeEmployee> >(); var fakeDbModel = new FakeEmployee(); var mockDbContext = new Mock <ISalaryCalculatorDbContext>(); mockDbContext.Setup(mock => mock.Set <FakeEmployee>()).Returns(fakeDbSet.Object); var repo = new SalaryCalculatorRepository <FakeEmployee>(mockDbContext.Object); // Act repo.Add(fakeDbModel); // Assert mockDbContext.Verify(mock => mock.Entry(It.IsAny <FakeEmployee>()), Times.Once()); }