public void ThrowArgumentNullException_WhenSportshallNameIsNull() { //Arrange var dbContextMock = new Mock <ISportscardSystemDbContext>(); var mapperMock = new Mock <IMapper>(); var expectedSportshall = new Sportshall() { Name = null, IsDeleted = true }; var data = new List <Sportshall>() { new Sportshall() { Name = "Pulse", IsDeleted = false } }; var mockSet = new Mock <DbSet <Sportshall> >(); mockSet.SetupData(data); dbContextMock.Setup(x => x.Sportshalls).Returns(mockSet.Object); var sportshallService = new SportshallService(dbContextMock.Object, mapperMock.Object); //Act&Assert Assert.ThrowsException <ArgumentNullException>(() => sportshallService.DeleteSportshall(expectedSportshall.Name)); }
public void InvokeSaveChangesMethod_WhenSportshallExistAtDb() { //Arrange var dbContextMock = new Mock <ISportscardSystemDbContext>(); var mapperMock = new Mock <IMapper>(); var expectedSportshall = new Sportshall() { Name = "Pulse", IsDeleted = true }; var data = new List <Sportshall>() { new Sportshall() { Name = "Pulse", IsDeleted = false } }; var mockSet = new Mock <DbSet <Sportshall> >(); mockSet.SetupData(data); dbContextMock.Setup(x => x.Sportshalls).Returns(mockSet.Object); var sportshallService = new SportshallService(dbContextMock.Object, mapperMock.Object); //Act sportshallService.DeleteSportshall(expectedSportshall.Name); //Assert dbContextMock.Verify(x => x.SaveChanges(), Times.Once); Assert.AreEqual(expectedSportshall.IsDeleted, true); }