Ejemplo n.º 1
0
        public void Should_create_private_constructor_property_be_null()
        {
            var instance = SampleBuilder.Create <SampleDataClass>();

            instance.Should().NotBeNull();
            instance.SampleDataPrivateConstructorSubClass.Should().BeNull();
        }
Ejemplo n.º 2
0
        public void Should_fill_generic_list_interface_property()
        {
            var sample = SampleBuilder.Create <SampleDataClass>();

            sample.SampleDataSimpleSubClassIListInterface.Should().NotBeNullOrEmpty();
            sample.SampleDataSimpleSubClassIListInterface[0].IntProperty.Should().Be(1168);
        }
Ejemplo n.º 3
0
        public void Publish_should_send_object_as_json_message_to_queue()
        {
            var exchangeName = $"Exchange_{MethodBase.GetCurrentMethod().Name}_{Guid.NewGuid()}";
            var queueName    = $"Queue_{MethodBase.GetCurrentMethod().Name}_{Guid.NewGuid()}";
            var routingKey   = $"RoutingKey_{MethodBase.GetCurrentMethod().Name}_{Guid.NewGuid()}";

            var sampleClass = SampleBuilder.Create <SerializableSampleClass>();

            _rabbit
            .Connect()
            .CreateQueue(queueName)
            .CreateExchange(exchangeName)
            .Bind(
                p =>
            {
                p.RoutingKey   = routingKey;
                p.QueueName    = queueName;
                p.ExchangeName = exchangeName;
            }
                )
            .Publish(sampleClass,
                     p =>
            {
                p.ExchangeName  = exchangeName;
                p.RoutingKey    = routingKey;
                p.PayloadFormat = PayloadFormat.ByteArray;
            })
            .DeleteQueue(queueName)
            .DeleteExchange(exchangeName)
            .Dispose();
        }
Ejemplo n.º 4
0
        protected override string CreateBody(ThreadSample threadSample)
        {
            var pprof         = new Pprof();
            var sampleBuilder = new SampleBuilder();

            pprof.AddLabel(sampleBuilder, "source.event.time", threadSample.Timestamp.Milliseconds);

            if (threadSample.SpanId != 0 || threadSample.TraceIdHigh != 0 || threadSample.TraceIdLow != 0)
            {
                pprof.AddLabel(sampleBuilder, "span_id", threadSample.SpanId);
                pprof.AddLabel(sampleBuilder, "trace_id", TraceIdHelper.ToString(threadSample.TraceIdHigh, threadSample.TraceIdLow));
            }

            foreach (var methodName in threadSample.Frames)
            {
                sampleBuilder.AddLocationId(pprof.GetLocationId(methodName));
            }

            pprof.AddLabel(sampleBuilder, "thread.id", threadSample.ManagedId);
            pprof.AddLabel(sampleBuilder, "thread.name", threadSample.ThreadName);
            pprof.AddLabel(sampleBuilder, "thread.os.id", threadSample.NativeId);

            pprof.Profile.Samples.Add(sampleBuilder.Build());
            return(Serialize(pprof.Profile));
        }
Ejemplo n.º 5
0
        public void Should_create_sample_data_for_a_class_having_public_parameter_constructor()
        {
            var instance = SampleBuilder.Create <ClassHavingArguments>();

            instance.Priority.Should().Be(866);
            instance.Type.Should().Be(nameof(instance.Type));
            instance.Value.Should().Be(nameof(instance.Value));
        }
Ejemplo n.º 6
0
        public void Should_fill_simple_sub_class_property()
        {
            var sample = SampleBuilder.Create <SampleDataClass>();

            sample.SampleDataSimpleSubClass.Should().NotBeNull();
            sample.SampleDataSimpleSubClass.IntProperty.Should().Be(1168);
            sample.SampleDataSimpleSubClass.StringProperty.Should().Be("StringProperty");
        }
Ejemplo n.º 7
0
        private void AddLabel(SampleBuilder sampleBuilder, string name, Action <Label> setLabel)
        {
            var label = new Label {
                Key = _stringTable.Get(name)
            };

            setLabel(label);
            sampleBuilder.AddLabel(label);
        }
Ejemplo n.º 8
0
        public void Should_fill_generic_list_property()
        {
            var sample = SampleBuilder.Create <SampleDataClass>();

            sample.SampleDataSimpleSubClassList.Should().NotBeNull();
            sample.SampleDataSimpleSubClassList.Count.Should().Be(2);

            sample.SampleDataSimpleSubClassList[0].IntProperty.Should().Be(1168);
        }
Ejemplo n.º 9
0
        public void AddLabel(SampleBuilder sample, string name, string value)
        {
            if (value == null)
            {
                return;
            }

            AddLabel(sample, name, label => label.Str = _stringTable.Get(value));
        }
Ejemplo n.º 10
0
        public void Should_be_create_new_sample_with_constructor()
        {
            //Arrange
            //Act
            var p1 = SampleBuilder.Create <SampleUser>();

            //Assert
            p1.Should().NotBeNull();
        }
Ejemplo n.º 11
0
        public void Should_create_sample_data_for_having_another_class_as_property()
        {
            var instance = SampleBuilder.Create <ClassHavingAnotherClassAsProperty>();

            instance.Address.Should().NotBeNull();
            instance.Address.Name.Should().Be(nameof(instance.Address.Name));
            instance.Address.AdditionalLines.Count.Should().Be(2);
            instance.Address.AdditionalLines[0].Should().Be("AdditionalLines_0");
            instance.Address.AdditionalLines[1].Should().Be("AdditionalLines_1");
        }
        public async Task SendMessage_should_throw_exception_when_http_response_is_null()
        {
            var httpClient = HttpClientExtensions.CreateMockHttpClient <object>(null);

            var client = CreateClient(httpClient: httpClient);

            await Assert.ThrowsAsync <Exception>(
                () => client.SendMessage(SampleBuilder.Create <DefaultMicrosoftTeamsPostMessage>())
                );
        }
Ejemplo n.º 13
0
        public void Should_create_sample_for_SampleEnumNoElementClass()
        {
            //Arrange
            //Act
            var p1 = SampleBuilder.Create <SampleEnumNoElementClass>();

            //Assert
            p1.Should().NotBeNull();
            p1.SampleEnumNoElementEnumProperty.Should().Be(0);
        }
Ejemplo n.º 14
0
        public void Should_be_nullable_enum_class_be_filled()
        {
            //Arrange
            //Act
            var p1 = SampleBuilder.Create <SampleNullableEnumClass>();

            //Assert
            p1.Should().NotBeNull();
            p1.SampleNullableEnum.Should().Be(SampleNullableEnum.OnlyItem);
        }
Ejemplo n.º 15
0
        public void Should_fill_primitive_values()
        {
            var now    = DateTime.Now;
            var sample = SampleBuilder.Create <SampleDataClass>(null, p =>
            {
                p.AlwaysUseDateTimeAs       = now;
                p.AlwaysUseDateTimeAddition = SampleDateTimeAdditions.AddMinutes;
            });

            sample.Should().NotBeNull();
            sample.BooleanProperty.Should().BeTrue();
            sample.BooleanPropertyNullable.Should().BeTrue();

            sample.ByteProperty.Should().Be(1273 / 128);
            sample.BytePropertyNullable.Should().Be(2088 / 128);

            sample.DateTimeProperty.Should().Be(now.AddMinutes(1650)); //adds days according to name
            sample.DateTimePropertyNullable.Should().Be(now.AddMinutes(2465));

            sample.DecimalProperty.Should().Be(1556); //number is calculated according to name
            sample.DecimalPropertyNullable.Should().Be(2371);

            sample.DoubleProperty.Should().Be(1472);
            sample.DoublePropertyNullable.Should().Be(2287);

            sample.FloatProperty.Should().Be(1371);
            sample.FloatPropertyNullable.Should().Be(2186);

            sample.Int16Property.Should().Be(1271);
            sample.Int16PropertyNullable.Should().Be(2086);

            sample.Int64Property.Should().Be(1274);
            sample.Int64PropertyNullable.Should().Be(2089);

            sample.IntProperty.Should().Be(1168);
            sample.IntPropertyNullable.Should().Be(1983);

            sample.SingleProperty.Should().Be(1479);
            sample.SinglePropertyNullable.Should().Be(2294);

            sample.StringProperty.Should().Be("StringProperty");
            sample.StringPropertyNullable.Should().Be("StringPropertyNullable");

            sample.UInt16Property.Should().Be(1356);
            sample.UInt16PropertyNullable.Should().Be(2171);

            sample.UInt64Property.Should().Be(1359);
            sample.UInt64PropertyNullable.Should().Be(2174);

            sample.UIntProperty.Should().Be(1253);
            sample.UIntPropertyNullable.Should().Be(2068);

            sample.GuidProperty.Should().Be(Guid.Parse("00000000-0000-0000-0000-000000000001"));
            sample.GuidPropertyNullable.Should().Be(Guid.Parse("00000000-0000-0000-0000-000000000001"));
        }
Ejemplo n.º 16
0
        public void Should_create_and_fill_when_having_ilist_interface_property()
        {
            var now      = DateTime.Now;
            var instance = SampleBuilder.Create <ClassHavingIListInterfaceAsProperty>(null, p =>
            {
                p.AlwaysUseDateTimeAs = now;
            });

            instance.Should().NotBeNull();
            instance.IListInterfaceProperty.Should().NotBeNullOrEmpty();
        }
Ejemplo n.º 17
0
        public void Should_create_sample_data_for_inherited_class()
        {
            var instance = SampleBuilder.Create <InheritedClass>();

            instance.Addressing.Should().Be(nameof(instance.Addressing));
            instance.City.Should().Be(nameof(instance.City));
            instance.CountryIsoAlpha2Code.Should().Be(nameof(instance.CountryIsoAlpha2Code));
            instance.AdditionalLines.Count.Should().Be(2);
            instance.AdditionalLines[0].Should().Be("AdditionalLines_0");
            instance.AdditionalLines[1].Should().Be("AdditionalLines_1");
        }
Ejemplo n.º 18
0
        public void Seconds_returns_other_builder(int value, SampleBuilder otherBuilder)
        {
            // Arrange
            var builder = TimespanBuilder.Create(value, otherBuilder);

            // Act
            var result = builder.Seconds();

            // Assert
            Assert.That(result, Is.SameAs(otherBuilder));
        }
Ejemplo n.º 19
0
        public void Should_fill_inherited_sub_class_property()
        {
            var now    = DateTime.Now;
            var sample = SampleBuilder.Create <SampleDataClass>(null, p =>
            {
                p.AlwaysUseDateTimeAs       = now;
                p.AlwaysUseDateTimeAddition = SampleDateTimeAdditions.AddSeconds;
            });

            sample.SampleDataInheritedSubClass.Should().NotBeNull();
            sample.SampleDataInheritedSubClass.DateTimeProperty.Should().Be(now.AddSeconds(1650));
        }
Ejemplo n.º 20
0
        public void Minutes_can_build_a_matching_timespan(int value, SampleBuilder otherBuilder)
        {
            // Arrange
            var builder          = TimespanBuilder.Create(value, otherBuilder);
            var timespanProvider = (IProvidesTimespan)builder;

            // Act
            builder.Minutes();

            // Assert
            Assert.That(timespanProvider.GetTimespan(), Is.EqualTo(TimeSpan.FromMinutes(value)));
        }
Ejemplo n.º 21
0
        public void Should_fill_primitive_constructor_sub_class_property()
        {
            var now    = DateTime.Now;
            var sample = SampleBuilder.Create <SampleDataClass>(null, p =>
            {
                p.AlwaysUseDateTimeAs       = now;
                p.AlwaysUseDateTimeAddition = SampleDateTimeAdditions.AddDays;
            });

            sample.SampleDataPrimitiveConstructorSubClass.Should().NotBeNull();
            sample.SampleDataPrimitiveConstructorSubClass.DateTimeProperty.Should().Be(now.AddDays(1650));
        }
Ejemplo n.º 22
0
        public void Should_be_nullable_enum_class_be_filled_and_enum_index_1_picked()
        {
            //Arrange
            //Act
            var p1 = SampleBuilder.Create <SampleNullableEnumClass>(new SampleBuilderConfiguration()
            {
                AlwaysPickEnumItemIndex = 1
            });

            //Assert
            p1.Should().NotBeNull();
            p1.SampleNullableEnum.Should().Be(SampleNullableEnum.OnlyItem2);
        }
Ejemplo n.º 23
0
        public void Should_create_sample_data_with_config(string prefix, string suffix, string result)
        {
            var instance = SampleBuilder.Create <ClassHavingNoArguments>(null,
                                                                         p =>
            {
                p.AlwaysUsePrefixForStringAs = prefix;
                p.AlwaysUseSuffixForStringAs = suffix;
            });

            instance.Priority.Should().Be(866);
            instance.Type.Should().Be(string.Format(result, nameof(instance.Type)));
            instance.Value.Should().Be(string.Format(result, nameof(instance.Value)));
        }
Ejemplo n.º 24
0
        public async Task SendMessage_should_throw_exception_when_http_response_messageid_is_null()
        {
            var httpClient = HttpClientExtensions.CreateMockHttpClient(new DefaultMicrosoftTeamsReplyMessageResponse()
            {
                MessageId = null
            });

            var client = CreateClient(httpClient: httpClient);

            await Assert.ThrowsAsync <Exception>(
                () => client.SendMessage(SampleBuilder.Create <DefaultMicrosoftTeamsReplyMessage>())
                );
        }
Ejemplo n.º 25
0
        public async void IBuilderBuild()
        {
            IBuilder substituteBuilder = new SampleBuilder();
            var      newNullObject     = new NULLObject();
            var      builder           = substituteBuilder
                                         .With(newNullObject);

            Assert.NotNull(substituteBuilder);
            Assert.AreSame(substituteBuilder, builder);

            var result = await builder.Build();

            Assert.AreSame(result, newNullObject);
        }
Ejemplo n.º 26
0
        public void Should_use_same_config_and__not_equal()
        {
            //Arrange
            var config = new SampleBuilderConfiguration()
            {
                AlwaysUseDateTimeAs = DateTime.Now
            };

            //Act
            var p1 = SampleBuilder.Create <SampleDataClassForEquality>(config);
            var p2 = SampleBuilder.Create <SampleDataClassForEquality>(p => p.IntValue = -1, config);

            //Assert
            p1.Should().NotBe(p2);
        }
Ejemplo n.º 27
0
        public void Should_dictionary_initialized()
        {
            var config = new SampleBuilderConfiguration()
            {
                CollectionCount = 2
            };
            //Act
            var p1 = SampleBuilder.Create <SampleDataWithDictionary>(config);

            //Assert
            p1.DictionaryProperty.Should().NotBeNull();
            //p1.DictionaryProperty.Should().HaveCount(config.CollectionCount);
            //p1.DictionaryProperty.Keys.First().Should().Be(0);
            //p1.DictionaryProperty.Keys.Last().Should().Be(1);
        }
Ejemplo n.º 28
0
        public void Should_be_recursive_list_property_must_be_filled()
        {
            //Arrange
            //Act
            var p1 = SampleBuilder.Create <SampleRecursiveListClass.A>();

            //Assert
            p1.Should().NotBeNull();
            p1.Ref_B.Ref_C.Ref_A_list.Should().NotBeNull();
            p1.Ref_B.Ref_C.Ref_A_list.Count.Should().Be(2);
            p1.Ref_B.Ref_C.Ref_A_list[0].Should().NotBeNull();
            p1.Ref_B.Ref_C.Ref_A_list[0].Ref_B.Should().NotBeNull();
            p1.Ref_B.Ref_C.Ref_A_list[0].Ref_B.Ref_C.Should().NotBeNull();
            p1.Ref_B.Ref_C.Ref_A_list[0].Ref_B.Ref_C.Ref_A_list.Should().NotBeNull();
            p1.Ref_B.Ref_C.Ref_A_list[0].Ref_B.Ref_C.Ref_A_list[0].Should().NotBeNull();
        }
Ejemplo n.º 29
0
        public void Values_given_to_extension_method___correct_Sample()
        {
            double[] values   = { 1, 2, 3 };
            var      expected = new Sample(values);

            var sut = new SampleBuilder();

            values.AddToSampleBuilder(sut).ToList();

            Sample actual = sut.GetSample();

            Assert.Multiple(() =>
            {
                CollectionAssert.AreEqual(expected.Values, actual.Values);
                Assert.AreEqual(expected.ToString(), actual.ToString());
            });
        }
Ejemplo n.º 30
0
        public void Should_create_and_fill_company()
        {
            var now      = DateTime.Now;
            var instance = SampleBuilder.Create <Company>(null, p =>
            {
                p.AlwaysUseDateTimeAs       = now;
                p.AlwaysUseDateTimeAddition = SampleDateTimeAdditions.AddDays;
            });

            instance.Should().NotBeNull();

            instance.CompanyId.Should().Be(900);
            instance.Branches.Should().NotBeNull();
            instance.Closed.Should().Be(now.AddDays(602));

            instance.MainAddress.Should().NotBeNull();
        }