public void Add_ShouldCallUpdateMethod_WhenThePackegeExists_ButWithLowerVersion_WithException()
        {
            //Arrange
            var loggerMock   = new Mock <ILogger>();
            var packagesMock = new Mock <IPackage>();

            packagesMock.Setup(x => x.CompareTo(It.IsAny <IPackage>())).Returns(1);

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

            var sut = new PackageRepositoryMock(loggerMock.Object);

            //Act
            sut.Add(packagesMock.Object);

            //Assert
            Assert.Throws <UpdateMethodCalledException>(() => sut.Add(packagesMock.Object));
        }
示例#2
0
        public void CallUpdateMethod_WhenThePackageAddedAlreadyWithLowerVersion_WithException()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger>();
            var packageMock = new Mock <IPackage>();

            packageMock.Setup(x => x.CompareTo(It.IsAny <IPackage>())).Returns(1);

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

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

            // Act & Assert
            Assert.Throws <UpdateMethodCalledException>(() => repository.Add(packageMock.Object));
        }
示例#3
0
        public void CallUpdateMethodAndThrowException_WhenTheAlreadyAddedPackageIsWithLowerVersion()
        {
            // Arrange
            var loggerMock  = new Mock <ILogger>();
            var packageMock = new Mock <IPackage>();

            packageMock.Setup(p => p.Name).Returns("Package");
            packageMock.Setup(p => p.CompareTo(It.IsAny <IPackage>())).Returns(1);

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

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

            // Act && Assert
            Assert.Throws <UpdateMethodCalledException>(() => packageRepository.Add(packageMock.Object));
        }