Exemplo n.º 1
0
        public void UpdateAdvert_Should_CallSaveChangesTwoTimes_IfAdvertIsValid()
        {
            // Arrange & Act
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advert            = new Mock <Advert>();
            var secondAdvert      = new Mock <Advert>();

            // Act
            advertService.UpdateAdvert(advert.Object);
            advertService.UpdateAdvert(secondAdvert.Object);

            // Assert
            mockedSaveChanges.Verify(u => u.SaveChanges(), Times.Exactly(2));
        }
Exemplo n.º 2
0
        public void UpdateAdvert_ShouldThrowNullReferenceException_IfAdvertIsNull()
        {
            // Arrange & Act
            var           mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var           mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var           advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            Mock <Advert> advertAsNull      = null;

            // Assert
            Assert.Throws <NullReferenceException>(() => advertService.UpdateAdvert(advertAsNull.Object));
        }
Exemplo n.º 3
0
        public void UpdateAdvert_Should_BeCalled_IfAdvertIsValid()
        {
            // Arrange
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advertToUpdate    = new Mock <Advert>();

            // Act
            advertService.UpdateAdvert(advertToUpdate.Object);

            // Assert
            mockedDbSet.Verify(rep => rep.Update(advertToUpdate.Object), Times.Once);
        }