AddOrUpdatePublishConfiguration() public method

public AddOrUpdatePublishConfiguration ( string configurationName, string publishLocation, string apiKey ) : IServiceResult
configurationName string
publishLocation string
apiKey string
return IServiceResult
        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 AddOrUpdatePublishConfiguration_ConfigurationNameParameterIsInvalid_ArgumentExceptionIsThrown(string configurationName)
        {
            // Arrange
            string publishLocation = "http://nuget.org/api/v2";
            string apiKey = null;

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

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

            // Act
            configFilePublishConfigurationAccessor.AddOrUpdatePublishConfiguration(configurationName, publishLocation, apiKey);
        }
        public void AddOrUpdatePublishConfiguration_PublishConfigurationFactoryReturnsNull_ResultIsFalse()
        {
            // 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[]>>();

            PublishConfiguration createdPublishConfiguration = null;
            publishConfigurationFactory.Setup(p => p.GetPublishConfiguration(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(createdPublishConfiguration);

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

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

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }