public void GetConfiguration_KomfoSharpNodeIsAbsent_ThrowsException()
    {
      // Arrange
      var xmlSource = Substitute.For<IXmlSource>();
      var configurationFactory = new AppConfigConfigurationProvider(xmlSource);
      xmlSource.GetXml().Returns((XmlNode)null);

      // Act, Assert
      configurationFactory
        .Invoking((x) => x.GetConfiguration())
        .ShouldThrow<InvalidOperationException>()
        .WithMessage("Could not retrieve the 'komfoSharp' configuration node.");
    }
    public void GetConfiguration_EndpointsNodeIsAbsent_ThrowsException()
    {
      // Arrange
      var configuration = XDocument.Parse(@"<komfoSharp>
                                              <polling defaultTimeInterval='00:00:10' defaultAttemptsCount='6'/>
                                            </komfoSharp>");

      var xmlSource = Substitute.For<IXmlSource>();
      var configurationFactory = new AppConfigConfigurationProvider(xmlSource);
      xmlSource.GetXml().Returns(ToXmlDocument(configuration).SelectSingleNode("komfoSharp"));

      // Act, Assert
      configurationFactory
        .Invoking((x) => x.GetConfiguration())
        .ShouldThrow<InvalidOperationException>()
        .WithMessage("Could not retrieve the 'komfoSharp/services/endpoints' configuration node.");
    }
    public void GetConfiguration_MaxEntriesPerCallIsNotSetForCustomAudienceUsersEndpoint_ThrowsException()
    {
      // Arrange
      var configuration = XDocument.Parse(@"<komfoSharp>
                                              <services>
                                                <endpoints baseUrl='https://connect.komfo.com'>
                                                  <customAudienceUsers path='/v1/ads/customaudiences/{audience_id}/users' />
                                                </endpoints>
                                              </services>
                                              <polling defaultTimeInterval='00:00:10' defaultAttemptsCount='6'/>
                                            </komfoSharp>");

      var xmlSource = Substitute.For<IXmlSource>();
      var configurationFactory = new AppConfigConfigurationProvider(xmlSource);
      xmlSource.GetXml().Returns(ToXmlDocument(configuration).SelectSingleNode("komfoSharp"));

      // Act, Assert
      configurationFactory
        .Invoking((x) => x.GetConfiguration())
        .ShouldThrow<InvalidOperationException>()
        .WithMessage("There were errors during deserializing the 'komfoSharp/services/endpoints/customAudienceUsers' node into the KomfoSharp.Configuration.Endpoints.CustomAudienceUsersEndpoint type. See inner exception for details.");
    }
    public void GetConfiguration_PollingNodeIsAbsent_ThrowsException()
    {
      // Arrange
      var configuration = XDocument.Parse(@"<komfoSharp>
                                              <services>
                                                <endpoints baseUrl='https://connect.komfo.com'>
                                                  <tokens path='/oauth20/tokens' />
                                                  <stream path='/v1/twitter/followers/stream' maxTwitterHandlesPerCall='100' maxResultsPerCall='1000'/>
                                                  <metrics path='/v1/twitter/followers/metrics' maxTwitterHandlesPerCall='100' />
                                                </endpoints>
                                              </services>
                                            </komfoSharp>");

      var xmlSource = Substitute.For<IXmlSource>();
      var configurationFactory = new AppConfigConfigurationProvider(xmlSource);
      xmlSource.GetXml().Returns(ToXmlDocument(configuration).SelectSingleNode("komfoSharp"));

      // Act, Assert
      configurationFactory
        .Invoking((x) => x.GetConfiguration())
        .ShouldThrow<InvalidOperationException>()
        .WithMessage("Could not retrieve the 'komfoSharp/polling' configuration node.");
    }
    public void GetConfiguration_MaxResultsPerCallIsNotSetForStreamEndpoint_ThrowsException()
    {
      // Arrange
      var configuration = XDocument.Parse(@"<komfoSharp>
                                              <services>
                                                <endpoints baseUrl='https://connect.komfo.com'>
                                                  <tokens path='/oauth20/tokens' />
                                                  <stream path='/v1/twitter/followers/stream' maxTwitterHandlesPerCall='100' />
                                                  <metrics path='/v1/twitter/followers/metrics' maxTwitterHandlesPerCall='100' />
                                                </endpoints>
                                              </services>
                                              <polling defaultTimeInterval='00:00:10' defaultAttemptsCount='6'/>
                                            </komfoSharp>");

      var xmlSource = Substitute.For<IXmlSource>();
      var configurationFactory = new AppConfigConfigurationProvider(xmlSource);
      xmlSource.GetXml().Returns(ToXmlDocument(configuration).SelectSingleNode("komfoSharp"));

      // Act, Assert
      configurationFactory
        .Invoking((x) => x.GetConfiguration())
        .ShouldThrow<InvalidOperationException>()
        .WithMessage("There were errors during deserializing the 'komfoSharp/services/endpoints/stream' node into the KomfoSharp.Configuration.Endpoints.StreamEndpoint type. See inner exception for details.");
    }
    public void GetConfiguration_BaseUrlInvalid_ThrowsException()
    {
      // Arrange
      var configuration = XDocument.Parse(@"<komfoSharp>
                                              <services>
                                                <endpoints baseUrl='invalid'>
                                                  <tokens path='/oauth20/tokens' />
                                                  <stream path='/v1/twitter/followers/stream' maxTwitterHandlesPerCall='100' maxResultsPerCall='1000'/>
                                                  <metrics path='/v1/twitter/followers/metrics' maxTwitterHandlesPerCall='100' />
                                                </endpoints>
                                              </services>
                                              <polling defaultTimeInterval='00:00:10' defaultAttemptsCount='6'/>
                                            </komfoSharp>");

      var xmlSource = Substitute.For<IXmlSource>();
      var configurationFactory = new AppConfigConfigurationProvider(xmlSource);
      xmlSource.GetXml().Returns(ToXmlDocument(configuration).SelectSingleNode("komfoSharp"));

      // Act, Assert
      configurationFactory
        .Invoking((x) => x.GetConfiguration())
        .ShouldThrow<InvalidOperationException>()
        .WithMessage("The 'baseUrl' value should be a valid URL.");
    }