public void AddOrUpdatePublishConfiguration_ConfigDoesNotYetExist_NewEntryIsPersisted()
        {
            // Arrange
            string configurationName = "Some Config Name";
            string publishLocation = "http://nuget.org/api/v2";
            string apiKey = Guid.NewGuid().ToString();

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var publishConfigurationFactory = new Mock<IPublishConfigurationFactory>();
            var publishConfigurationPersistence = new Mock<IFilesystemPersistence<PublishConfiguration[]>>();

            var createdPublishConfiguration = new PublishConfiguration { Name = configurationName, PublishLocation = publishLocation, ApiKey = apiKey };
            publishConfigurationFactory.Setup(p => p.GetPublishConfiguration(configurationName, publishLocation, apiKey)).Returns(createdPublishConfiguration);

            var existingConfigurations = new PublishConfiguration[] { };
            publishConfigurationPersistence.Setup(p => p.Load(It.IsAny<string>())).Returns(existingConfigurations);

            var configFilePublishConfigurationAccessor = new ConfigFilePublishConfigurationAccessor(
                applicationInformation, publishConfigurationFactory.Object, publishConfigurationPersistence.Object);

            // Act
            configFilePublishConfigurationAccessor.AddOrUpdatePublishConfiguration(configurationName, publishLocation, apiKey);

            // Assert
            publishConfigurationPersistence.Verify(
                p => p.Save(It.Is<PublishConfiguration[]>(configs => configs.First().Equals(createdPublishConfiguration)), It.IsAny<string>()), Times.Once());
        }
        public void Equals_SuppliedObjectIsOfOtherType_ResultIsFalse()
        {
            // Arrange
            var publishConfiguration1 = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2" };
            object publishConfiguration2 = new object();

            // Act
            bool result = publishConfiguration1.Equals(publishConfiguration2);

            // Assert
            Assert.IsFalse(result);
        }
        public void Equals_TwoIdenticalConfigurations_ResultIsTrue()
        {
            // Arrange
            var publishConfiguration1 = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2" };
            var publishConfiguration2 = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2" };

            // Act
            bool result = publishConfiguration1.Equals(publishConfiguration2);

            // Assert
            Assert.IsTrue(result);
        }
        public void CanBeDeserialized()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2" };

            // Act
            string json = JsonConvert.SerializeObject(publishConfiguration);
            var deserializedpublishConfiguration = JsonConvert.DeserializeObject<PublishConfiguration>(json);

            // Assert
            Assert.AreEqual(publishConfiguration.Name, deserializedpublishConfiguration.Name);
            Assert.AreEqual(publishConfiguration.PublishLocation, deserializedpublishConfiguration.PublishLocation);
        }
        public void Serialize_PublishConfiguration_JsonContainsAllProperties()
        {
            // Arrange
            var jsonObjectSerializer = new JSONObjectSerializer<PublishConfiguration>();

            var name = Guid.NewGuid().ToString();
            var location = Guid.NewGuid().ToString();
            var apiKey = Guid.NewGuid().ToString();
            var publishConfiguration = new PublishConfiguration { Name = name, PublishLocation = location, ApiKey = apiKey };

            // Act
            var result = jsonObjectSerializer.Serialize(publishConfiguration);

            // Assert
            Assert.IsTrue(result.Contains(name));
            Assert.IsTrue(result.Contains(location));
            Assert.IsTrue(result.Contains(apiKey));
        }
        public void Load_PublishConfiguration_ObjectDeserializerReturnsEmptyPublishConfiguration_ResultIsEmptyPublishConfiguration()
        {
            // Arrange
            PublishConfiguration objectReturnedByDeserializer = new PublishConfiguration();
            string storageLocation = "temp-file";

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var objectSerializer = new Mock<IObjectSerializer<PublishConfiguration>>();

            filesystemAccessor.Setup(f => f.FileExists(It.IsAny<string>())).Returns(true);
            filesystemAccessor.Setup(f => f.GetFileContent(It.IsAny<string>())).Returns("some content");
            objectSerializer.Setup(s => s.Deserialize(It.IsAny<string>())).Returns(objectReturnedByDeserializer);

            var filesystemPersistence = new FilesystemPersistence<PublishConfiguration>(filesystemAccessor.Object, objectSerializer.Object);

            // Act
            var result = filesystemPersistence.Load(storageLocation);

            // Assert
            Assert.AreEqual(objectReturnedByDeserializer, result);
        }
        public void IsValid_PropertyIsNotSerialed()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2" };

            // Act
            string json = JsonConvert.SerializeObject(publishConfiguration);

            // Assert
            string isValidPropertyName =
                typeof(PublishConfiguration).GetProperties().First(p => p.Name.Equals("isvalid", StringComparison.OrdinalIgnoreCase)).Name;

            Assert.IsFalse(json.ToLower().Contains(isValidPropertyName.ToLower()));
        }
        public void IsValid_NameIsWhitespace_ResultIsFalse()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration { Name = " ", PublishLocation = "http://nuget.org/api/v2" };

            // Act
            bool result = publishConfiguration.IsValid;

            // Assert
            Assert.IsFalse(result);
        }
        public void PublishPackage_PackageStreamIsNull_ResultIsFalse()
        {
            // Arrange
            string packagePath = @"C:\local-nuget-repo\package.nupkg";
            string packageServerConfigurationName = "Nuget.org Publish Config";

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var packageServerFactory = new Mock<IPackageServerFactory>();
            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();

            Stream packageStream = null;
            filesystemAccessor.Setup(f => f.FileExists(packagePath)).Returns(true);
            filesystemAccessor.Setup(f => f.GetReadStream(packagePath)).Returns(packageStream);

            var publishConfiguration = new PublishConfiguration { Name = packageServerConfigurationName, PublishLocation = "http://nuget.org/api/v2" };
            publishConfigurationAccessor.Setup(p => p.GetPublishConfiguration(packageServerConfigurationName)).Returns(publishConfiguration);

            var packageServer = new PackageServer(publishConfiguration.PublishLocation, NuDeployConstants.NuDeployCommandLinePackageId);
            packageServerFactory.Setup(p => p.GetPackageServer(It.IsAny<string>())).Returns(packageServer);

            var publishingService = new PublishingService(filesystemAccessor.Object, packageServerFactory.Object, publishConfigurationAccessor.Object);

            // Act
            var result = publishingService.PublishPackage(packagePath, packageServerConfigurationName);

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
        public void Save_PublishConfiguration_ObjectSerializerReturnInvalidResult_ResultIsFalse(string objectSerializerResult)
        {
            // Arrange
            var objectToPersist = new PublishConfiguration();
            string storageLocation = "temp-file";

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var objectSerializer = new Mock<IObjectSerializer<PublishConfiguration>>();

            objectSerializer.Setup(o => o.Serialize(It.IsAny<PublishConfiguration>())).Returns(objectSerializerResult);

            var filesystemPersistence = new FilesystemPersistence<PublishConfiguration>(filesystemAccessor.Object, objectSerializer.Object);

            // Act
            var result = filesystemPersistence.Save(objectToPersist, storageLocation);

            // Assert
            Assert.IsFalse(result);
        }
        public void ToString_PublishLocationIsNull_ResultContainsName()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = null };

            // Act
            string result = publishConfiguration.ToString();

            // Assert
            Assert.IsTrue(result.Contains(publishConfiguration.Name));
        }
        public void ToString_ContainsRepositoryPublishLocation()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2" };

            // Act
            string result = publishConfiguration.ToString();

            // Assert
            Assert.IsTrue(result.Contains(publishConfiguration.PublishLocation));
        }
        public void ToString_ContainsApiKeyPlaceHolder_IfNotSet()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2", ApiKey = null };

            // Act
            string result = publishConfiguration.ToString();

            // Assert
            Assert.IsTrue(result.Contains("not-set"));
        }
        public void GetHashCode_TwoIdenticalObjects_BothUninitialized_HashCodesAreEqual()
        {
            // Arrange
            var publishConfiguration1 = new PublishConfiguration();
            var publishConfiguration2 = new PublishConfiguration();

            // Act
            int hashCodeObject1 = publishConfiguration1.GetHashCode();
            int hashCodeObject2 = publishConfiguration2.GetHashCode();

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
        public void GetHashCode_TwoIdenticalObjects_BothInitialized_HashCodesAreEqual()
        {
            // Arrange
            var publishConfiguration1 = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2" };
            var publishConfiguration2 = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2" };

            // Act
            int hashCodeObject1 = publishConfiguration1.GetHashCode();
            int hashCodeObject2 = publishConfiguration2.GetHashCode();

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
        public void GetHashCode_SameHashCodeIsReturnedEveryTimeTheMethodIsCalled_AsLongAsTheObjectDoesNotChange()
        {
            // Arrange
            string repositoryName = "Some Repository";
            string repositoryPublishLocation = "http://example.com";
            var publishConfiguration = new PublishConfiguration { Name = repositoryName, PublishLocation = repositoryPublishLocation };

            int expectedHashcode = publishConfiguration.GetHashCode();

            for (var i = 0; i < 100; i++)
            {
                // Act
                publishConfiguration.Name = repositoryName;
                publishConfiguration.PublishLocation = repositoryPublishLocation;
                int generatedHashCode = publishConfiguration.GetHashCode();

                // Assert
                Assert.AreEqual(expectedHashcode, generatedHashCode);
            }
        }
        public void GetHashCode_ForAllUniqueObject_AUniqueHashCodeIsReturned()
        {
            var hashCodes = new Dictionary<int, PublishConfiguration>();

            for (var i = 0; i < 10000; i++)
            {
                // Act
                var publishConfiguration = new PublishConfiguration { Name = Guid.NewGuid().ToString(), PublishLocation = "http://" + Guid.NewGuid().ToString() };

                int generatedHashCode = publishConfiguration.GetHashCode();

                // Assert
                Assert.IsFalse(hashCodes.ContainsKey(generatedHashCode));
                hashCodes.Add(generatedHashCode, publishConfiguration);
            }
        }
 private bool SaveNewPublishConfigurationList(PublishConfiguration[] configurations)
 {
     return this.publishConfigurationPersistence.Save(configurations, this.configurationFilePath);
 }
Exemplo n.º 19
0
        public void PublishPackage_PublishConfigurationAccessorReturnsInvalidConfiguration_ResultIsFalse()
        {
            // Arrange
            string packagePath = @"C:\local-nuget-repo\package.nupkg";
            string packageServerConfigurationName = "Nuget.org Publish Config";

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var packageServerFactory = new Mock<IPackageServerFactory>();
            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();

            filesystemAccessor.Setup(f => f.FileExists(packagePath)).Returns(true);

            var publishConfiguration = new PublishConfiguration();
            publishConfigurationAccessor.Setup(p => p.GetPublishConfiguration(packageServerConfigurationName)).Returns(publishConfiguration);

            var publishingService = new PublishingService(filesystemAccessor.Object, packageServerFactory.Object, publishConfigurationAccessor.Object);

            // Act
            var result = publishingService.PublishPackage(packagePath, packageServerConfigurationName);

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
        public void IsValid_PublishLocationIsNull_ResultIsFalse()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = null };

            // Act
            bool result = publishConfiguration.IsValid;

            // Assert
            Assert.IsFalse(result);
        }
        public void Serialization_IsValidPropertyIsNotSerialized()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2" };

            // Act
            string json = JsonConvert.SerializeObject(publishConfiguration);

            // Assert
            Assert.IsFalse(json.Contains("IsValid"));
            Assert.IsFalse(json.Contains(publishConfiguration.IsValid.ToString(CultureInfo.InvariantCulture)));
        }
        public void Save_PublishConfiguration_WriteSerializedJsonToStoreageLocation_Suceeeds_ResultIsTrue()
        {
            // Arrange
            var objectToPersist = new PublishConfiguration();
            string storageLocation = "temp-file";

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var objectSerializer = new Mock<IObjectSerializer<PublishConfiguration>>();

            objectSerializer.Setup(o => o.Serialize(It.IsAny<PublishConfiguration>())).Returns("[]");
            filesystemAccessor.Setup(f => f.WriteContentToFile(It.IsAny<string>(), It.IsAny<string>())).Returns(true);

            var filesystemPersistence = new FilesystemPersistence<PublishConfiguration>(filesystemAccessor.Object, objectSerializer.Object);

            // Act
            var result = filesystemPersistence.Save(objectToPersist, storageLocation);

            // Assert
            Assert.IsTrue(result);
        }
        public void ToString_ContainsPublishLocationPlaceHolder_IfNotSet()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = null, ApiKey = "Some Api Key" };

            // Act
            string result = publishConfiguration.ToString();

            // Assert
            Assert.IsTrue(result.Contains("not-set"));
        }
        public void IsLocal_PublishLocationIsAbsolute_IsRemoteLocation_ResultIsFalse(string publishLocation)
        {
            // Arrage
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = publishLocation };

            // Act
            var result = publishConfiguration.IsLocal;

            // Assert
            Assert.IsFalse(result);
        }
        public void ToString_PropertiesAreNotSet_ResultIsTypeName()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration();

            // Act
            string result = publishConfiguration.ToString();

            // Assert
            Assert.AreEqual(typeof(PublishConfiguration).Name, result);
        }
        public void GetPublishConfiguration_ConfigurationNameParameterIsValid_PublishConfigurationPersistenceReturnsNoEntries_ResultIsNull()
        {
            // Arrange
            string configurationName = "Some non existing Configuration";

            var applicationInformation = new ApplicationInformation { ConfigurationFileFolder = Environment.CurrentDirectory };
            var publishConfigurationFactory = new Mock<IPublishConfigurationFactory>();
            var publishConfigurationPersistence = new Mock<IFilesystemPersistence<PublishConfiguration[]>>();

            var persitedConfigurations = new PublishConfiguration[] { };
            publishConfigurationPersistence.Setup(p => p.Load(It.IsAny<string>())).Returns(persitedConfigurations);

            var configFilePublishConfigurationAccessor = new ConfigFilePublishConfigurationAccessor(
                applicationInformation, publishConfigurationFactory.Object, publishConfigurationPersistence.Object);

            // Act
            var result = configFilePublishConfigurationAccessor.GetPublishConfiguration(configurationName);

            // Assert
            Assert.IsNull(result);
        }
        public void Save_PublishConfiguration_StorageLocationIsInvalid_ArgumentExceptionIsThrown(string storageLocation)
        {
            // Arrange
            var objectToPersist = new PublishConfiguration();

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var objectSerializer = new Mock<IObjectSerializer<PublishConfiguration>>();

            var filesystemPersistence = new FilesystemPersistence<PublishConfiguration>(filesystemAccessor.Object, objectSerializer.Object);

            // Act
            filesystemPersistence.Save(objectToPersist, storageLocation);
        }
        public void IsSerializable()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2" };

            // Act
            string json = JsonConvert.SerializeObject(publishConfiguration);

            // Assert
            Assert.IsTrue(json.Contains(publishConfiguration.Name));
            Assert.IsTrue(json.Contains(publishConfiguration.PublishLocation));
        }
        public void IsLocal_PublishLocationIsRelative_ResultIsTrue(string publishLocation)
        {
            // Arrage
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = publishLocation };

            // Act
            var result = publishConfiguration.IsLocal;

            // Assert
            Assert.IsTrue(result);
        }
        public void IsValid_NameIsSet_PublishLocationIsSet_ResultIsTrue()
        {
            // Arrange
            var publishConfiguration = new PublishConfiguration { Name = "Some Repository", PublishLocation = "http://nuget.org/api/v2" };

            // Act
            bool result = publishConfiguration.IsValid;

            // Assert
            Assert.IsTrue(result);
        }