Exemplo n.º 1
0
        public void Delete_PassValidPackage_ShouldReturnThePackage()
        {
            // Arrange
            var loggerMock = new Mock <ILogger>();

            loggerMock.Setup(l => l.Log(It.Is <string>(s => s == "PackageOne: The package was added!")));

            var versionMock = new Mock <IVersion>();

            versionMock.SetupGet(v => v.Major).Returns(1);
            versionMock.SetupGet(v => v.Minor).Returns(1);
            versionMock.SetupGet(v => v.Patch).Returns(1);
            versionMock.SetupGet(v => v.VersionType).Returns((VersionType)1);

            var packageMock = new Mock <IPackage>();

            packageMock.SetupGet(p => p.Name).Returns("PackageOne");
            packageMock.SetupGet(p => p.Version).Returns(versionMock.Object);
            packageMock.Setup(p => p.Equals(It.IsAny <object>())).Returns(true);
            packageMock.Setup(p => p.Dependencies).Returns(new List <IPackage>()
            {
                packageMock.Object
            });

            var packageRepository = new PackageRepository(loggerMock.Object);

            // Act
            packageRepository.Add(packageMock.Object);
            var result = packageRepository.Delete(packageMock.Object);

            // Assert
            Assert.AreSame(packageMock.Object, result);
        }
        public void NotRemovePackage_WhenPassedPackageIsADependencyToSomeOtherPackage()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger>();
            var packages    = new HashSet <IPackage>();
            var packageMock = new Mock <IPackage>();
            var packageWithDependencyMock = new Mock <IPackage>();

            packageWithDependencyMock.Setup(x => x.Dependencies).Returns(new List <IPackage>()
            {
                packageMock.Object
            });
            packageWithDependencyMock.Setup(x => x.Equals(It.IsAny <IPackage>())).Returns(true);

            packageMock.Setup(x => x.Name).Returns("nqma me");
            packageMock.Setup(x => x.Equals(It.IsAny <IPackage>())).Returns(true);
            packageMock.Setup(x => x.Dependencies).Returns(new List <IPackage>()
            {
                packageWithDependencyMock.Object
            });

            packages.Add(packageMock.Object);
            var countBeforeDelete = packages.Count;

            var repo = new PackageRepository(loggerMock.Object, packages);

            // Act & Assert
            // Added the exception
            Assert.Throws <InvalidOperationException>(() => repo.Delete(packageMock.Object));
            loggerMock.Verify(x => x.Log($"{packageMock.Object.Name}: The package is a dependency and could not be removed!"), Times.Once);
        }
        public void Delete_ShouldReturnPackageDeleted_WhenPackageDeletedSuccessfully()
        {
            var loggerMock  = new Mock <ILogger>();
            var packageMock = new Mock <IPackage>();

            packageMock.Setup(x => x.Name).Returns("name");
            packageMock.Setup(x => x.Url).Returns("url");
            packageMock.Setup(x => x.Dependencies).Returns(new List <IPackage>());
            packageMock.Setup(x => x.Version.Major).Returns(6);
            packageMock.Setup(x => x.Version.Minor).Returns(2);
            packageMock.Setup(x => x.Version.Patch).Returns(5);
            packageMock.Setup(x => x.Version.VersionType).Returns(Enums.VersionType.alpha);

            packageMock.Setup(x => x.CompareTo(It.IsAny <IPackage>())).Returns(0);
            packageMock.Setup(x => x.Equals(packageMock.Object)).Returns(true);

            var collection = new List <IPackage>()
            {
                packageMock.Object,
            };

            var sut = new PackageRepository(loggerMock.Object, collection);

            //Act
            var removedPackage = sut.Delete(packageMock.Object);

            //Assert
            Assert.AreEqual(packageMock.Object, removedPackage);
        }
Exemplo n.º 4
0
        public void ReturnPackageDeleted_WhenThePackageIsDeletedSuccessfullyFromTheCollection()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger>();
            var packageMock = new Mock <IPackage>();

            packageMock.SetupGet(x => x.Name).Returns("test");
            packageMock.SetupGet(x => x.Version.Major).Returns(1);
            packageMock.SetupGet(x => x.Version.Minor).Returns(1);
            packageMock.SetupGet(x => x.Version.Patch).Returns(1);
            packageMock.SetupGet(x => x.Version.VersionType).Returns(VersionType.alpha);

            packageMock.Setup(x => x.CompareTo(It.IsAny <IPackage>())).Returns(0);
            packageMock.Setup(x => x.Equals(packageMock.Object)).Returns(true);
            packageMock.Setup(x => x.Dependencies).Returns(new List <IPackage>());

            var collection = new List <IPackage>()
            {
                packageMock.Object,
            };

            var repository = new PackageRepository(loggerMock.Object, collection);

            // Act
            var packageRemoved = repository.Delete(packageMock.Object);

            // Assert
            Assert.AreEqual(packageMock.Object, packageRemoved);
        }
        public void ReturnTheRemovedPackage_WhenPackageIsSuccessfullyRemoved()
        {
            // arrange
            var loggerStub = new Mock <ILogger>();

            var presentPackage = new Mock <IPackage>();

            presentPackage.Setup(x => x.Equals(It.IsAny <IPackage>()))
            .Returns(true);

            var dependencies = new List <IPackage>();

            presentPackage.Setup(x => x.Dependencies).Returns(dependencies);

            var packageToRemove = new Mock <IPackage>();

            var repositoryPackages = new List <IPackage>()
            {
                presentPackage.Object
            };
            var packageRepo = new PackageRepository(loggerStub.Object, repositoryPackages);;

            // act
            var returnedObj = packageRepo.Delete(packageToRemove.Object);

            // assert
            Assert.AreSame(packageToRemove.Object, returnedObj);
        }
        public void LogThreeTimes_WhenPackageIsADependencyOfAnotherPackage()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger>();
            var packageMock = new Mock <IPackage>();
            var packageMockWithDependency = new Mock <IPackage>();

            packageMock.Setup(p => p.Equals(packageMock.Object)).Returns(true);
            packageMock.Setup(p => p.Dependencies).Returns(new List <IPackage>());

            packageMockWithDependency.Setup(p => p.Dependencies).Returns(new List <IPackage>()
            {
                packageMock.Object
            });

            ICollection <IPackage> packages = new List <IPackage>()
            {
                packageMock.Object,
                packageMockWithDependency.Object
            };

            PackageRepository packageRepository = new PackageRepository(loggerMock.Object, packages);

            // Act
            packageRepository.Delete(packageMock.Object);

            // Assert
            loggerMock.Verify(l => l.Log(It.IsAny <string>()), Times.Exactly(3));
        }
        public void Delete_ShouldNotAnyExceptions_WhenMethodInvokedAndPackageFound()
        {
            //Arrange
            var loggerMock             = new Mock <ILogger>();
            var packagesCollectionMock = new Mock <IPackage>();

            var versionMock = new Mock <IVersion>();

            versionMock.Setup(x => x.Major).Returns(5);
            versionMock.Setup(x => x.Minor).Returns(2);
            versionMock.Setup(x => x.Patch).Returns(6);
            versionMock.Setup(x => x.VersionType).Returns(Enums.VersionType.alpha);

            packagesCollectionMock.Setup(x => x.Name).Returns("name");
            packagesCollectionMock.Setup(x => x.Url).Returns("url");
            packagesCollectionMock.Setup(x => x.Version).Returns(versionMock.Object);
            packagesCollectionMock.Setup(x => x.Dependencies).Returns(new List <IPackage>());

            packagesCollectionMock.Setup(x => x.Equals(packagesCollectionMock.Object)).Returns(true);

            var collection = new List <IPackage>()
            {
                packagesCollectionMock.Object
            };

            var sut = new PackageRepository(loggerMock.Object, collection);


            //Act & Assert
            Assert.DoesNotThrow(() => sut.Delete(packagesCollectionMock.Object));
        }
Exemplo n.º 8
0
        public void Delete_PassValidPackageWithDependencies_ShouldFailToDelete_LogMessage()
        {
            // Arrange
            var loggerMock = new Mock <ILogger>();

            loggerMock.Setup(l => l.Log(It.Is <string>(s => s == "PackageOne: The package was added!")));

            var versionMock = new Mock <IVersion>();

            versionMock.SetupGet(v => v.Major).Returns(1);
            versionMock.SetupGet(v => v.Minor).Returns(1);
            versionMock.SetupGet(v => v.Patch).Returns(1);
            versionMock.SetupGet(v => v.VersionType).Returns((VersionType)1);

            var packageMock = new Mock <IPackage>();

            packageMock.SetupGet(p => p.Name).Returns("PackageOne");
            packageMock.SetupGet(p => p.Version).Returns(versionMock.Object);
            packageMock.Setup(p => p.Equals(It.IsAny <object>())).Returns(true);
            packageMock.Setup(p => p.Dependencies).Returns(new List <IPackage>()
            {
                packageMock.Object
            });

            var packageRepository = new PackageRepository(loggerMock.Object);

            // Act
            packageRepository.Add(packageMock.Object);
            packageRepository.Delete(packageMock.Object);

            // Assert
            loggerMock.Verify(l => l.Log(It.Is <string>(s => s == "PackageOne: The package is a dependency and could not be removed!")));
        }
Exemplo n.º 9
0
        public void ThrowArgumentNullExceptionWhenPassedPackageIsNull()
        {
            //Arrange
            var packagesMock = Mock.Create <List <IPackage> >();
            var logerMock    = Mock.Create <ILogger>();
            var sut          = new PackageRepository(logerMock, packagesMock);

            //Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => sut.Delete(null));
        }
Exemplo n.º 10
0
        public void ThrowArgumentNullException_WhenPackageIsNull()
        {
            // Arrange
            var loggerMock = new Mock <ILogger>();

            PackageRepository packageRepository = new PackageRepository(loggerMock.Object);

            // Act && Assert
            Assert.Throws <ArgumentNullException>(() => packageRepository.Delete(null));
        }
        public void ThrowArgumentNullException_WhenPassedPackageIsNull()
        {
            // arrange
            var loggerStub = new Mock <ILogger>();

            var packageRepo = new PackageRepository(loggerStub.Object);

            // act and assert
            Assert.Throws <ArgumentNullException>(() => packageRepo.Delete(null));
        }
Exemplo n.º 12
0
        public void Delete_PassInvalidNullPackage_ShouldThrowArgumentNullException()
        {
            // Arrange
            var loggerMock = new Mock <ILogger>();

            var packageRepository = new PackageRepository(loggerMock.Object);

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => packageRepository.Delete(null));
        }
Exemplo n.º 13
0
        public void ThrowArgumentNullException_WhenPassedPackageObjIsNull()
        {
            // Arrange
            var loggerMock = new Mock <ILogger>();
            var packages   = new HashSet <IPackage>();
            var repo       = new PackageRepository(loggerMock.Object, packages);

            // Act & Assert
            var ex = Assert.Throws <ArgumentNullException>(() => repo.Delete(null));

            StringAssert.Contains("Package cannot be null", ex.Message);
        }
        public void Delete_ShouldThrowArgumentNullException_WhenMethodInvokedAndNoPackageFound_WithMessage()
        {
            //Arrange
            var loggerMock             = new Mock <ILogger>();
            var packagesCollectionMock = new Mock <IPackage>();

            var sut = new PackageRepository(loggerMock.Object);

            //Act & Assert
            Assert.Throws <ArgumentNullException>(() => sut.Delete(packagesCollectionMock.Object));
            loggerMock.Verify(x => x.Log(It.IsAny <string>()), Times.Once);
        }
Exemplo n.º 15
0
        public void ThrowArgumentNullException_WhenPackageIsNotFound()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger>();
            var packageMock = new Mock <IPackage>();

            PackageRepository packageRepository = new PackageRepository(loggerMock.Object);

            // Act && Assert
            Assert.Throws <ArgumentNullException>(() => packageRepository.Delete(packageMock.Object));
            loggerMock.Verify(l => l.Log(It.IsAny <string>()), Times.Once());
        }
Exemplo n.º 16
0
        public void ThrowArgumentNullException_WhenPassedPackageIsNull()
        {
            // Arrange
            var loggerMock = new Mock <ILogger>();
            // var packageMock = new Mock<IPackage>();

            // var packages = new List<IPackage> { packageMock.Object };

            var packageRepsitory = new PackageRepository(loggerMock.Object);

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => packageRepsitory.Delete(null));
        }
        public void Delete_ShouldThrowArgumenNullException_WhenPassedParameterIsNull()
        {
            //Arrange
            string message = "Package cannot be null";

            var loggerMock   = new Mock <ILogger>();
            var packagesMock = new Mock <ICollection <IPackage> >();

            var sut = new PackageRepository(loggerMock.Object, packagesMock.Object);

            //Act & Assert
            Assert.That(() => sut.Delete(null), Throws.ArgumentNullException.With.Message.Contains(message));
        }
Exemplo n.º 18
0
        public void Delete(long id)
        {
            var files_old = new List <Int64>(GetPackageFiles(id).Select(m => m.Id));

            var unit_of_work = UnitOfWorkProvider.GetUnitOfWork();

            unit_of_work.BeginTransaction();

            PackageRepository.Delete(id);

            unit_of_work.Commit();

            ReturnStatusForFiles(files_old);
        }
Exemplo n.º 19
0
        public void ThrowArgumentNullExcseption_WhenPassedPackageDoesNotExistInThePackagesList()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger>();
            var packages    = new HashSet <IPackage>();
            var packageMock = new Mock <IPackage>();

            packageMock.Setup(x => x.Name).Returns("nqma me");

            var repo = new PackageRepository(loggerMock.Object, packages);

            // Act & Assert
            var ex = Assert.Throws <ArgumentNullException>(() => repo.Delete(packageMock.Object));

            StringAssert.Contains("Package cannot be null", ex.Message);
            loggerMock.Verify(x => x.Log($"{packageMock.Object.Name}: The package does not exist!"), Times.Once);
        }
        public void Delete(Ingredient ingredient)
        {
            using (StorageDbContext context = new StorageDbContext())
            {
                context.Configuration.AutoDetectChangesEnabled = false;
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        PackageRepository package           = new PackageRepository();
                        ProductRepository productRepository = new ProductRepository();
                        IngredientsForProductRepository ingredientsForProductRepository = new IngredientsForProductRepository();

                        package.Delete(ingredient);

                        var allReceiptsWithEntryIngredients = ingredientsForProductRepository.GetDataSource().Where(n => n.IngredientId == ingredient.Id).ToList();
                        if (allReceiptsWithEntryIngredients != null)
                        {
                            foreach (var oneIngredientForProductInReceipt in allReceiptsWithEntryIngredients)
                            {
                                Product productWithEntryIngredientInReceipt = productRepository.GetDataSource().First(n => n.Id == oneIngredientForProductInReceipt.ProductId);

                                productRepository.Delete(productWithEntryIngredientInReceipt);
                            }
                        }

                        context.Configuration.ValidateOnSaveEnabled = false;
                        context.Ingredients.Attach(ingredient);
                        context.Entry(ingredient).State = EntityState.Deleted;
                        context.ChangeTracker.DetectChanges();
                        context.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw new InvalidOperationException("Помилка видалення.");
                    }
                    finally
                    {
                        context.Configuration.ValidateOnSaveEnabled = true;
                    }
                }
            }
        }
        public void AddandDeleteTest()
        {
            List <Package> expected = ExpectedPackages();
            Package        package  = new Package()
            {
                Id = 3, name = "Cool"
            };

            expected.Add(package);
            repo.Add(package);
            List <Package> actual  = repo.ReadAll();
            Package        actuall = actual.Last();

            Assert.IsTrue(comparer(package, actuall));

            repo.Delete(package.Id);
            expected.Remove(package);

            Assert.IsTrue(listcomparer(repo.ReadAll(), expected));
        }
Exemplo n.º 22
0
        public void NotThrowException_WhenPassedPackageIsValid()
        {
            var loggerMock          = new Mock <ILogger>();
            var packageMock         = new Mock <IPackage>();
            var packageToDeleteMock = new Mock <IPackage>();

            packageMock.SetupGet(x => x.Name).Returns("SomeName");
            packageToDeleteMock.SetupGet(x => x.Name).Returns("OtherName");

            var packages = new List <IPackage> {
                packageMock.Object
            };

            var packageRepsitory = new PackageRepository(loggerMock.Object, packages);

            packageMock.Setup(x => x.Equals(It.IsAny <IPackage>())).Returns(true);

            // Act and Assert
            Assert.DoesNotThrow(() => packageRepsitory.Delete(packageToDeleteMock.Object));
        }
        public void ThrowArgumentNullException_WhenNoPassedPackageCannotBeFoundInPackagesCollection()
        {
            // arrange
            var loggerStub = new Mock <ILogger>();

            var presentPackage = new Mock <IPackage>();

            presentPackage.Setup(x => x.Equals(It.IsAny <IPackage>()))
            .Returns(false);
            var repositoryPackages = new List <IPackage>()
            {
                presentPackage.Object
            };

            var packageRepo = new PackageRepository(loggerStub.Object, repositoryPackages);;

            var packageToRemove = new Mock <IPackage>();

            // act and assert
            Assert.Throws <ArgumentNullException>(() => packageRepo.Delete(packageToRemove.Object));
        }
Exemplo n.º 24
0
        public void ReturnTheDeletedPackage_WhenThePackageIsDeletedSuccessfullyFromTheCollection()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger>();
            var packageMock = new Mock <IPackage>();

            packageMock.Setup(p => p.Equals(packageMock.Object)).Returns(true);
            packageMock.Setup(p => p.Dependencies).Returns(new List <IPackage>());

            ICollection <IPackage> packages = new List <IPackage>()
            {
                packageMock.Object
            };

            PackageRepository packageRepository = new PackageRepository(loggerMock.Object, packages);

            // Act
            IPackage deletedPackage = packageRepository.Delete(packageMock.Object);

            // Assert
            Assert.AreEqual(packageMock.Object, deletedPackage);
        }
        public void Delete_ShouldLogMessageThreeTimes_WhenPackageWithSuchVersionIsAddedAlreadt()
        {
            var loggerMock  = new Mock <ILogger>();
            var packageMock = new Mock <IPackage>();

            packageMock.Setup(x => x.Name).Returns("name");
            packageMock.Setup(x => x.Url).Returns("url");
            packageMock.Setup(x => x.Dependencies).Returns(new List <IPackage>());
            packageMock.Setup(x => x.Version.Major).Returns(6);
            packageMock.Setup(x => x.Version.Minor).Returns(2);
            packageMock.Setup(x => x.Version.Patch).Returns(5);
            packageMock.Setup(x => x.Version.VersionType).Returns(Enums.VersionType.alpha);

            packageMock.Setup(x => x.CompareTo(It.IsAny <IPackage>())).Returns(0);
            packageMock.Setup(x => x.Equals(packageMock.Object)).Returns(true);

            var packageMockAdded = new Mock <IPackage>();

            packageMockAdded.Setup(x => x.Dependencies).Returns(new List <IPackage>()
            {
                packageMock.Object
            });

            packageMockAdded.Setup(x => x.Equals(It.IsAny <IPackage>())).Returns(false);

            var collection = new List <IPackage>()
            {
                packageMock.Object,
                packageMockAdded.Object
            };

            var sut = new PackageRepository(loggerMock.Object, collection);

            //Act
            sut.Delete(packageMock.Object);

            //Assert
            loggerMock.Verify(x => x.Log(It.IsAny <string>()), Times.Exactly(3));
        }
Exemplo n.º 26
0
        public void ReturnTheRemovedPackage_WhenDeleteMethodWasSuccessful()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger>();
            var packages    = new HashSet <IPackage>();
            var packageMock = new Mock <IPackage>();

            packageMock.Setup(x => x.Name).Returns("nqma me");
            packageMock.Setup(x => x.Equals(It.IsAny <IPackage>())).Returns(true);
            packageMock.Setup(x => x.Dependencies).Returns(new List <IPackage>());

            packages.Add(packageMock.Object);
            var countBeforeDelete = packages.Count;

            var repo = new PackageRepository(loggerMock.Object, packages);

            // Act
            var deletedPackage = repo.Delete(packageMock.Object);

            // Assert
            Assert.AreSame(packageMock.Object, deletedPackage);
        }
        public void CallLoggersLogMethodWithStringContainingpackageIsAdependencyAndCouldNotBeRemoved_WhenPackageIsFoundButIsADependencOfOtherPackagesInCollection()
        {
            // arrange
            var loggerStub = new Mock <ILogger>();

            var presentPackage = new Mock <IPackage>();

            presentPackage.Setup(x => x.Equals(It.IsAny <IPackage>()))
            .Returns(true);

            var dependency = new Mock <IPackage>();

            dependency.Setup(x => x.Equals(It.IsAny <IPackage>())).Returns(true);
            dependency.Setup(x => x.Dependencies).Returns(new List <IPackage>());

            var dependencies = new List <IPackage>()
            {
                dependency.Object
            };

            presentPackage.Setup(x => x.Dependencies).Returns(dependencies);

            var packageToRemove = new Mock <IPackage>();

            var repositoryPackages = new List <IPackage>()
            {
                presentPackage.Object
            };
            var packageRepo = new PackageRepository(loggerStub.Object, repositoryPackages);;

            loggerStub.Setup(x => x.Log(It.Is <string>(y => y.Contains("The package is a dependency and could not be removed"))));

            // act
            var ex = Assert.Throws <ArgumentException>(() => packageRepo.Delete(packageToRemove.Object));

            // assert
            loggerStub.Verify(x => x.Log(It.Is <string>(y => y.Contains("The package is a dependency and could not be removed"))), Times.Once);
        }
Exemplo n.º 28
0
        public void PackageAlreadyExistMessageLogThreeTimes_WhenThePackageWithTheSameVersionIsAddedAlready()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger>();
            var packageMock = new Mock <IPackage>();

            packageMock.SetupGet(x => x.Name).Returns("test");
            packageMock.SetupGet(x => x.Version.Major).Returns(1);
            packageMock.SetupGet(x => x.Version.Minor).Returns(1);
            packageMock.SetupGet(x => x.Version.Patch).Returns(1);
            packageMock.SetupGet(x => x.Version.VersionType).Returns(VersionType.alpha);

            packageMock.Setup(x => x.CompareTo(It.IsAny <IPackage>())).Returns(0);
            packageMock.Setup(x => x.Equals(packageMock.Object)).Returns(true);
            packageMock.Setup(x => x.Dependencies).Returns(new List <IPackage>());
            var packageMockAddedToCollectionWithDependency = new Mock <IPackage>();

            packageMockAddedToCollectionWithDependency.Setup(x => x.Dependencies).Returns(new List <IPackage>()
            {
                packageMock.Object
            });

            packageMockAddedToCollectionWithDependency.Setup(x => x.Equals(It.IsAny <IPackage>())).Returns(false);

            var collection = new List <IPackage>()
            {
                packageMock.Object,
                packageMockAddedToCollectionWithDependency.Object
            };

            var repository = new PackageRepository(loggerMock.Object, collection);

            // Act
            repository.Delete(packageMock.Object);

            // Assert
            loggerMock.Verify(x => x.Log(It.IsAny <string>()), Times.Exactly(3));
        }
Exemplo n.º 29
0
        public void RemovePackageFromList_WhenPassedPackageExistInThePackagesList()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger>();
            var packages    = new HashSet <IPackage>();
            var packageMock = new Mock <IPackage>();

            packageMock.Setup(x => x.Name).Returns("nqma me");
            packageMock.Setup(x => x.Equals(It.IsAny <IPackage>())).Returns(true);
            packageMock.Setup(x => x.Dependencies).Returns(new List <IPackage>());

            packages.Add(packageMock.Object);
            var countBeforeDelete = packages.Count;

            var repo = new PackageRepository(loggerMock.Object, packages);

            // Act
            repo.Delete(packageMock.Object);

            // Assert
            Assert.AreEqual(1, countBeforeDelete);
            Assert.AreEqual(0, packages.Count);
        }
Exemplo n.º 30
0
        public void LogRespectiveMessageAndThrowArgumentNullException_WhenThePackageIsNotFound()
        {
            var someName         = "SomeName";
            var targetLogMessage = string.Format("{0}: The package does not exist!", someName);

            var loggerMock          = new Mock <ILogger>();
            var packageMock         = new Mock <IPackage>();
            var packageToDeleteMock = new Mock <IPackage>();

            packageMock.SetupGet(x => x.Name).Returns(someName);
            packageToDeleteMock.SetupGet(x => x.Name).Returns(someName);

            var packages = new List <IPackage> {
                packageMock.Object
            };

            var packageRepsitory = new PackageRepository(loggerMock.Object, packages);

            packageMock.Setup(x => x.Equals(It.IsAny <IPackage>())).Returns(false);

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => packageRepsitory.Delete(packageToDeleteMock.Object));
            loggerMock.Verify(x => x.Log(targetLogMessage), Times.Once);
        }