public void CanGetMemberNames(JsonObject input)
 => A3 <DynamicJsonObject>
 .Arrange(setup =>
 {
     var json = JsonSerializer.Serialize(input);
     setup.Sut((DynamicJsonObject)DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(json)));
 })
 .Act(sut => sut.GetDynamicMemberNames())
 .Assert(result => result.Should().Contain(nameof(JsonObject.Value)));
Exemple #2
0
 public void CanUseLogAvailability()
 => A3 <LoggerTelemetry>
 .Arrange <AvailabilityTelemetry>(setup =>
 {
     setup.Sut(new LoggerTelemetry(setup.Mock <ILogger>().Object, setup.Fixture.Create <TelemetryClient>()));
     return(setup.Fixture.Create <AvailabilityTelemetry>());
 })
 .Act((sut, telemetry) => sut.LogAvailability(telemetry))
 .Assert(context => { /* TelemetryClient cannot be mocked */ });
 public void CanAccessPropertyByIndexer(JsonObject input)
 => A3 <dynamic>
 .Arrange(setup =>
 {
     var json = JsonSerializer.Serialize(input);
     setup.Sut(DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(json)));
 })
 .Act(sut => (string?)sut[nameof(JsonObject.Value)])
 .Assert(result => result.Should().Be(input.Value));
 public void DynamicArrayIsSupported(int[] input)
 => A3 <dynamic>
 .Arrange(setup => setup.Sut(DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(JsonSerializer.Serialize(input)))))
 .Act(sut =>
 {
     dynamic[] result = sut;
     return(result);
 })
 .Assert(result => result.Length.Should().Be(input.Length));
Exemple #5
0
 public void IListOfTypeIsSupported(IList <T> input)
 => A3 <dynamic>
 .Arrange(setup => setup.Sut(DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(JsonSerializer.Serialize(input, JsonSerializerOptions), JsonSerializerOptions))))
 .Act(sut =>
 {
     IEnumerable <T> result = sut;
     return(result);
 })
 .Assert(result => result.Should().BeEquivalentTo(input));
Exemple #6
0
 public void AddApplicationInsightsPublisherShouldRegisterIHealthCheckPublisher()
 => A3 <ServiceCollection>
 .Arrange(setup =>
 {
     var services = new ServiceCollection();
     services.AddOptions();
     setup.Sut(services);
 })
 .Act(sut => { sut.AddHealthChecks().AddApplicationInsightsPublisher(); })
 .Assert(context => context.Sut.Any(x => x.ServiceType == typeof(IHealthCheckPublisher) && x.ImplementationType == typeof(ApplicationInsightsHealthCheckPublisher)).Should().BeTrue());
 public Task ShouldReturnTheValueFromTheValueProvider()
 => A3 <MvcModelValueProvider>
 .Arrange(setup =>
 {
     var type          = typeof(string);
     var valueProvider = new Func <object>(() => string.Empty);
     setup.Sut(new MvcModelValueProvider(type, valueProvider));
 })
 .Act(async sut => await sut.GetValueAsync().ConfigureAwait(false))
 .Assert(result => result.Should().NotBeNull());
 public void CanConvertJsonToDynamic(string input)
 => A3 <dynamic>
 .Arrange(setup =>
 {
     var options = new JsonSerializerOptions();
     options.Converters.Add(new DynamicJsonConverter());
     var json = JsonSerializer.Serialize(new { Input = input }, options);
     setup.Sut(JsonSerializer.Deserialize <dynamic>(json, options));
 })
 .Act(sut => (string)sut.Input)
 .Assert(result => result.Should().Be(input));
Exemple #9
0
 public void AfterAddApplicationInsightsPublisherShouldBeAbleToGetApplicationInsightsHealthCheckPublisherOptions()
 => A3 <IServiceProvider>
 .Arrange(setup =>
 {
     var services = new ServiceCollection();
     services.AddSingleton <IConfiguration>(new ConfigurationBuilder().Build());
     services.AddOptions();
     services.AddHealthChecks().AddApplicationInsightsPublisher();
     setup.Sut(services.BuildServiceProvider());
 })
 .Act(sut => sut.GetService <IOptions <ApplicationInsightsHealthCheckPublisherOptions> >())
 .Assert(result => result?.Value.Should().NotBeNull());
 public void JsonCanBeDeserializedToDynamicType(JsonObject input)
 => A3 <dynamic>
 .Arrange(setup =>
 {
     var json = JsonSerializer.Serialize(input);
     setup.Sut(DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(json)));
 })
 .Act(sut =>
 {
     JsonObject result = sut;
     return(result);
 })
 .Assert(result => result.Should().BeEquivalentTo(input));
Exemple #11
0
        public void ReadOnlyListPropertyIsPopulatedDuringDeserialization(JsonObject obj)
        => A3 <JsonSerializerOptions>
        .Arrange(setup =>
        {
            var json    = JsonSerializer.Serialize(obj);
            var options = new JsonSerializerOptions();
            options.Converters.Add(new JsonReadOnlyCollectionConverter());

            setup.Sut(options);
            setup.Parameter(json);
        })
        .Act((JsonSerializerOptions sut, string json) => JsonSerializer.Deserialize <JsonObject>(json, sut))
        .Assert(result => result.List.Should().BeEquivalentTo(obj.List));
 public void DictionaryIsSupported(IDictionary <string, string> input)
 => A3 <dynamic>
 .Arrange(setup =>
 {
     var json = JsonSerializer.Serialize(input);
     setup.Sut(DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(json)));
 })
 .Act(sut =>
 {
     IDictionary <string, string> result = sut;
     return(result);
 })
 .Assert(result => result.Should().BeEquivalentTo(input));
Exemple #13
0
        public void CanSerializeAndDeserializeTimeSpan(TimeSpan input)
        => A3 <JsonSerializerOptions>
        .Arrange(setup =>
        {
            var options = new JsonSerializerOptions();
            options.Converters.Add(new JsonTimeSpanConverter());

            var json = JsonSerializer.Serialize(input, options);

            setup.Sut(options);
            setup.Parameter(json);
        })
        .Act((JsonSerializerOptions sut, string json) => JsonSerializer.Deserialize <TimeSpan>(json, sut))
        .Assert(result => result.Should().Be(input));
Exemple #14
0
        public void WhenNullableTimeSpanIsNotNullThenCanSerializeAndDeserialize(JsonObject input)
        => A3 <JsonSerializerOptions>
        .Arrange(setup =>
        {
            var options = new JsonSerializerOptions();
            options.Converters.Add(new JsonTimeSpanConverter());

            var json = JsonSerializer.Serialize(input, options);

            setup.Sut(options);
            setup.Parameter(json);
        })
        .Act((JsonSerializerOptions sut, string json) => JsonSerializer.Deserialize <JsonObject>(json, sut))
        .Assert(result => result.Timestamp.Should().NotBeNull());
        public void AfterStartupThenTheMvcModelBindingProviderShouldBeRegisteredAsAnIBindingProvider()
        => A3 <ServiceCollection>
        .Arrange(setup =>
        {
            var services = new ServiceCollection();

            services.AddOptions();
            services.AddSingleton(setup.Mock <IHttpRequestStreamReaderFactory>().Object);

            setup.Mock <IWebJobsBuilder>(builder => builder.SetupGet(x => x.Services).Returns(services));

            setup.Sut(services);
            setup.Parameter(setup.Mock <IWebJobsBuilder>().Object);
        })
        .Act((ServiceCollection sut, IWebJobsBuilder builder) =>
        {
            new WebJobsStartup().Configure(builder);
            return(sut);
        })
        .Assert(result =>
Exemple #16
0
 public Task ShouldReturnTheValueFromTheValueProvider(string input)
 => A3 <ODataBindingValueProvider>
 .Arrange(setup => setup.Sut(new ODataBindingValueProvider(input)))
 .Act(async sut => await sut.GetValueAsync().ConfigureAwait(false))
 .Assert(result => result.Should().Be(input));
Exemple #17
0
 public void CanResolveILoggerTelemetryOfTFromServiceProvider()
 => A3 <IServiceProvider>
 .Arrange(setup => setup.Sut(setup.Fixture.Create <IServiceProvider>()))
 .Act(sut => sut.GetService <ILoggerTelemetry <LoggerTelemetrySerivceCollectionExtensionsTests> >())
 .Assert(result => result.Should().NotBeNull());
Exemple #18
0
 public void CanResolveILoggerTelemetryFactoryFromServiceProvider()
 => A3 <IServiceProvider>
 .Arrange(setup => setup.Sut(setup.Fixture.Create <IServiceProvider>()))
 .Act(sut => sut.GetService <ILoggerTelemetryFactory>())
 .Assert(result => result.Should().NotBeNull());
Exemple #19
0
 public void CanUseLogEvent()
 => A3 <LoggerTelemetry>
 .Arrange(setup => setup.Sut(new LoggerTelemetry(setup.Mock <ILogger>().Object, setup.Fixture.Create <TelemetryClient>())))
 .Act(sut => sut.LogEvent(nameof(CanUseLogEvent)))
 .Assert(context => { /* TelemetryClient cannot be mocked */ });
 public void Int32ArrayIsSupported(int[] input)
 => A3 <dynamic>
 .Arrange(setup => setup.Sut(DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(JsonSerializer.Serialize(input)))))
 .Act(sut => (int[])sut)
 .Assert(result => result.Should().BeEquivalentTo(input));
Exemple #21
0
 public void CanResolveILoggerTelemetryFromLoggerTelemetryFactory()
 => A3 <ILoggerTelemetryFactory>
 .Arrange(setup => setup.Sut(setup.Fixture.Create <IServiceProvider>().GetRequiredService <ILoggerTelemetryFactory>()))
 .Act(sut => sut.CreateLogger <LoggerTelemetrySerivceCollectionExtensionsTests>())
 .Assert(result => result.Should().NotBeNull());
 public void NullIsSupported()
 => A3 <dynamic>
 .Arrange(setup => setup.Sut(DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(JsonSerializer.Serialize <T?>(null, JsonSerializerOptions), JsonSerializerOptions))))
 .Act(sut => (T?)sut)
 .Assert(result => result.Should().BeNull());
 public void CanInvokeCountMethod(int[] input)
 => A3 <dynamic>
 .Arrange(setup => setup.Sut(DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(JsonSerializer.Serialize(input)))))
 .Act(sut => (int)sut.Count())
 .Assert(result => result.Should().Be(input.Length));
Exemple #24
0
 public void TypeIsSupported(T input)
 => A3 <dynamic>
 .Arrange(setup => setup.Sut(DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(JsonSerializer.Serialize(input, JsonSerializerOptions), JsonSerializerOptions))))
 .Act(sut => (T)sut)
 .Assert(result => result.Should().BeEquivalentTo(input));
Exemple #25
0
 public void CanUseLogTrace()
 => A3 <LoggerTelemetry>
 .Arrange(setup => setup.Sut(new LoggerTelemetry(setup.Mock <ILogger>().Object, setup.Fixture.Create <TelemetryClient>())))
 .Act(sut => sut.LogTrace(nameof(CanUseLogTrace)))
 .Assert(context => context.Mock <ILogger>().VerifyLog(logger => logger.LogTrace(It.IsAny <string>()), Times.Once));
Exemple #26
0
 public void CanUseBeginScope()
 => A3 <LoggerTelemetry>
 .Arrange(setup => setup.Sut(new LoggerTelemetry(setup.Mock <ILogger>().Object, setup.Fixture.Create <TelemetryClient>())))
 .Act(sut => { sut.BeginScope(this); })
 .Assert(context => context.Mock <ILogger>().Verify(x => x.BeginScope(It.IsAny <It.IsAnyType>()), Times.Once));
 public void ValueAsNumericIsSupported(T input)
 => A3 <dynamic>
 .Arrange(setup => setup.Sut(DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(JsonSerializer.Serialize(Convert.ChangeType(input, typeof(ulong)))))))
 .Act(sut => (T)sut)
 .Assert(result => result.Should().Be(input));
Exemple #28
0
 public void CanUseIsEnabled()
 => A3 <LoggerTelemetry>
 .Arrange(setup => setup.Sut(new LoggerTelemetry(setup.Mock <ILogger>().Object, setup.Fixture.Create <TelemetryClient>())))
 .Act(sut => { sut.IsEnabled(LogLevel.Trace); })
 .Assert(context => context.Mock <ILogger>().Verify(x => x.IsEnabled(LogLevel.Trace), Times.Once));
 public void CanReadLengthProperty(int[] input)
 => A3 <dynamic>
 .Arrange(setup => setup.Sut(DynamicJsonElement.From(JsonSerializer.Deserialize <JsonElement>(JsonSerializer.Serialize(input)))))
 .Act(sut => (int)sut.Length)
 .Assert(result => result.Should().Be(input.Length));