public void GenerateFormattedErrorMessage()
 {
     const string Expected = "400 BadRequest: This isn't going to happen";
     var sut = new SutBuilder<ErrorMessageGenerator>().Build();
     var result = sut.GenerateError(HttpStatusCode.BadRequest, "This isn't going to happen");
     Assert.AreEqual(Expected, result);
 }
        public void BuildClassWithNoConstructorArguments()
        {
            var sut = new SutBuilder<TestType>();

            var result = sut.Build();
            Assert.IsInstanceOfType(result, typeof(TestType));
        }
Esempio n. 3
0
        public void ComposeWithPostprocessorsReturnsCorrectResult()
        {
            // Fixture setup
            var postproc1 = new DelegatingSpecifiedSpecimenCommand <string>();
            var postproc2 = new DelegatingSpecifiedSpecimenCommand <string>();
            var postproc3 = new DelegatingSpecifiedSpecimenCommand <string>();

            var sut = new SutBuilder <string>().With(new[] { postproc1, postproc2, postproc3 }).Create();
            // Exercise system
            var result = sut.Compose();
            // Verify outcome
            var filter = result.IsFilter().ShouldSpecify <string>();

            var composite = Assert.IsAssignableFrom <CompositeSpecimenBuilder>(filter.Builder);

            var pp1 = Assert.IsAssignableFrom <Postprocessor <string> >(composite.Builders.First());

            Assert.Equal(postproc3.Execute, pp1.Action);

            var pp2 = Assert.IsAssignableFrom <Postprocessor <string> >(pp1.Builder);

            Assert.Equal(postproc2.Execute, pp2.Action);

            var pp3 = Assert.IsAssignableFrom <Postprocessor <string> >(pp2.Builder);

            Assert.Equal(postproc1.Execute, pp3.Action);

            var guard = Assert.IsAssignableFrom <NoSpecimenOutputGuard>(pp3.Builder);

            Assert.Equal(sut.Factory, guard.Builder);
            // Teardown
        }
        public void SutBuilderWithConstuctorWithParameters()
        {
            var sutBuilder = new SutBuilder <DemoClassWithServices>(new ConstructorProvider(), new MoqClassConstructor());
            var sut        = sutBuilder.Build();

            Assert.IsNotNull(sut);
        }
        public void SutBuilderStubs()
        {
            var sutBuilder = new SutBuilder();
            var sut        = sutBuilder.Build();

            Assert.IsNotNull(sut);
        }
        public void SutBuilderWithParameterlessConstuctor()
        {
            var sutBuilder = new SutBuilder <DemoSimpleClass>(new ParameterlessConstructorProvider(), new ClassConstructor());
            var sut        = sutBuilder.Build();

            Assert.IsNotNull(sut);
        }
Esempio n. 7
0
        public void Should_Format_Using_Additional_Injections_And_Configuration()
        {
            // given
            var argProvider = Substitute.For <IArgumentsProvider>();

            argProvider.GetArguments().Returns(new object[] { "guys" });

            var somethingMaker             = new SomethingMaker();
            var parametrizedSomethingMaker = new ParametrizedSomethingMaker(256);

            SutBuilder
            .Inject(
                somethingMaker,
                parametrizedSomethingMaker,
                argProvider)
            .Configure <IFormatProvider>(fp => fp.GetFormat().Returns("Goodbye {0}!"));

            var logger = SutBuilder.Get <IMyLogger>();

            // sut
            var sut = SutBuilder.Build();

            // when
            var result = sut.FormatMessage();

            // then
            logger.Received().Log("formatting ...");

            Assert.That(result, Is.EqualTo("Goodbye guys!"));
        }
        public void CreateHeader()
        {
            var expected = $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes(TestBasicCredentials))}";
            var sut = new SutBuilder<RequestHeaderFactory>().AddDependency(CreateSettings()).Build();

            Assert.AreEqual(expected, sut.AuthorizationHeader());
        }
Esempio n. 9
0
        public void Should_Format_Using_Default_Config_After_Reset()
        {
            /*
             * "Hello guys" case
             */

            // given
            var builder = new SutBuilder();

            builder.Configure <IArgumentsProvider>(ap => ap
                                                   .GetArguments()
                                                   .Returns(new object[] { "guys" }));

            // sut
            var sut = builder.Build();

            // when
            var result = sut.FormatMessage();

            // then
            Assert.That(result, Is.EqualTo("Hello guys!"));


            /*
             * "Hello world" case
             */

            // given
            builder.Reset();

            // sut
            sut = builder.Build();

            // when
            result = sut.FormatMessage();

            // then
            Assert.That(result, Is.EqualTo("Hello world!"));

            /*
             * "Hello dude" case
             */

            // given
            builder.Reset();

            builder.Configure <IArgumentsProvider>(ap => ap
                                                   .GetArguments()
                                                   .Returns(new object[] { "dude" }));

            // sut
            sut = builder.Build();

            // when
            result = sut.FormatMessage();

            // then
            Assert.That(result, Is.EqualTo("Hello dude!"));
        }
        public void GenerateFormattedErrorMessage()
        {
            const string Expected = "400 BadRequest: This isn't going to happen";
            var          sut      = new SutBuilder <ErrorMessageGenerator>().Build();
            var          result   = sut.GenerateError(HttpStatusCode.BadRequest, "This isn't going to happen");

            Assert.AreEqual(Expected, result);
        }
Esempio n. 11
0
        public void AutoDiscoverParameterNameOfDependency()
        {
            var expected = new TestType { Identifier = "Auto discovered parameter name" };
            var result = new SutBuilder<TestTypeWithConstructorArguments>().AddDependency(expected).Build();

            Assert.IsNotNull(result);
            Assert.AreEqual(expected.Identifier, result.TestType.Identifier);
            Assert.IsNull(result.TestType2.Identifier);
        }
Esempio n. 12
0
        public void WithNullPropertyPickerThrows()
        {
            // Fixture setup
            var sut = new SutBuilder <object>().Create();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.With <object>(null));
            // Teardown
        }
Esempio n. 13
0
        public void WithNullValueDoesNotThrow()
        {
            // Fixture setup
            var sut = new SutBuilder <PropertyHolder <object> >().Create();

            // Exercise system and verify outcome
            Assert.DoesNotThrow(() =>
                                sut.With(ph => ph.Property, null));
            // Teardown
        }
Esempio n. 14
0
        public void WithoutNullPropertyPickerThrows()
        {
            // Fixture setup
            var sut = new SutBuilder <UriPartial>().Create();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Without <ConsoleCancelEventArgs>(null));
            // Teardown
        }
Esempio n. 15
0
        public void FromNullQuadrupleParameterFactoryThrows()
        {
            // Fixture setup
            var sut = new SutBuilder <GenericUriParser>().Create();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.FromFactory <int, DateTime, AttributeTargets, LoaderOptimization>(null));
            // Teardown
        }
Esempio n. 16
0
        public void FromNullTripleParameterFactoryThrows()
        {
            // Fixture setup
            var sut = new SutBuilder <FileStyleUriParser>().Create();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.FromFactory <GenericUriParser, Base64FormattingOptions, LdapStyleUriParser>(null));
            // Teardown
        }
Esempio n. 17
0
        public void DoNullActionThrows()
        {
            // Fixture setup
            var sut = new SutBuilder <object>().Create();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Do(null));
            // Teardown
        }
Esempio n. 18
0
        public void FromNullParameterlessFactoryThrows()
        {
            // Fixture setup
            var sut = new SutBuilder <Guid>().Create();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.FromFactory((Func <Guid>)null));
            // Teardown
        }
Esempio n. 19
0
        public void FromNullSingleParameterFactoryThrows()
        {
            // Fixture setup
            var sut = new SutBuilder <DateTimeKind>().Create();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.FromFactory <ObsoleteAttribute>(null));
            // Teardown
        }
Esempio n. 20
0
        public void Should_Be_Able_To_Use_Descendant_Classes()
        {
            // given

            // when

            // then
            Assert.DoesNotThrow(() => SutBuilder.Inject(new SomethingElseMaker()));
            Assert.DoesNotThrow(() => SutBuilder.Inject(Substitute.For <SomethingElseMaker>()));
        }
Esempio n. 21
0
        public void SutIsFactoryComposer()
        {
            // Fixture setup
            // Exercise system
            var sut = new SutBuilder <object>().Create();

            // Verify outcome
            Assert.IsAssignableFrom <IFactoryComposer <object> >(sut);
            // Teardown
        }
Esempio n. 22
0
        public void FromNullDoubleParameterFactoryThrows()
        {
            // Fixture setup
            var sut = new SutBuilder <UnicodeEncoding>().Create();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.FromFactory <WeakReference, HttpStyleUriParser>(null));
            // Teardown
        }
Esempio n. 23
0
        public void BuildClassWithSingleOverriddenArgument()
        {
            var expected = new TestType { Identifier = "BuildClassWithSingleOverriddenArgument" };

            var sut = new SutBuilder<TestTypeWithConstructorArguments>();
            var result = sut.AddDependency(expected, "testType").Build();

            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result.TestType);
        }
        public static SentimentAnalysisService BuildSut(ISentimentAnalysisRequestor requestor)
        {
            var sut = new SutBuilder<SentimentAnalysisService>()
                .AddDependency(requestor)
                .AddDependency(new ViveknSettings())
                .AddDependency(new ErrorMessageGenerator())
                .Build();

            return sut;
        }
Esempio n. 25
0
        public void WithExplicitAutoPropertiesReturnsResultWithCorrectFactory()
        {
            // Fixture setup
            var sut = new SutBuilder <object>().Create();
            // Exercise system
            var result = sut.WithAutoProperties(true);

            // Verify outcome
            Assert.Equal(sut.Factory, result.Factory);
            // Teardown
        }
Esempio n. 26
0
        public void CreateAcceptHeader()
        {
            var expected = new MediaTypeWithQualityHeaderValue("application/json");
            var sut      = new SutBuilder <RequestHeaderFactory>().Build();

            using (var client = new HttpClient())
            {
                sut.SetHeaders(client.DefaultRequestHeaders);

                Assert.AreEqual(client.DefaultRequestHeaders.Accept.First(), expected);
            }
        }
Esempio n. 27
0
        public void WithFactoryReturnsResultWithCorrectFactory()
        {
            // Fixture setup
            var expectedFactory = new DelegatingSpecimenBuilder();
            var sut             = new SutBuilder <int>().Create();
            // Exercise system
            var result = sut.WithFactory(expectedFactory);

            // Verify outcome
            Assert.Equal(expectedFactory, result.Factory);
            // Teardown
        }
Esempio n. 28
0
        public void WithExplicitAutoPropertiesReturnsResultWithCorrectPostprocessors()
        {
            // Fixture setup
            var postprocessors = Enumerable.Range(1, 3).Select(i => new DelegatingSpecifiedSpecimenCommand <int>()).ToArray();
            var sut            = new SutBuilder <int>().With(postprocessors).Create();
            // Exercise system
            var result = sut.WithAutoProperties(false);

            // Verify outcome
            Assert.True(postprocessors.SequenceEqual(result.Postprocessors));
            // Teardown
        }
Esempio n. 29
0
        public void WithPostprocessorReturnsResultWithAddedPostprocessor()
        {
            // Fixture setup
            var expectedPostprocessor = new DelegatingSpecifiedSpecimenCommand <object>();
            var sut = new SutBuilder <object>().Create();
            // Exercise system
            var result = sut.WithPostprocessor(expectedPostprocessor);

            // Verify outcome
            Assert.Contains(expectedPostprocessor, result.Postprocessors);
            // Teardown
        }
        public void CreateAcceptHeader()
        {
            var expected = new MediaTypeWithQualityHeaderValue("application/json");
            var sut = new SutBuilder<RequestHeaderFactory>().Build();

            using (var client = new HttpClient())
            {
                sut.SetHeaders(client.DefaultRequestHeaders);

                Assert.AreEqual(client.DefaultRequestHeaders.Accept.First(), expected);
            }
        }
Esempio n. 31
0
        public void FromBuilderFactoryReturnsCorrectResult()
        {
            // Fixture setup
            var expectedFactory = new DelegatingSpecimenBuilder();
            var sut             = new SutBuilder <Version>().Create();
            // Exercise system
            var result = sut.FromFactory(expectedFactory);
            // Verify outcome
            var resultingComposer = Assert.IsAssignableFrom <Composer <Version> >(result);

            Assert.Equal(expectedFactory, resultingComposer.Factory);
            // Teardown
        }
Esempio n. 32
0
        public void WithPostprocessorReturnsResultWithCorrectFactory()
        {
            // Fixture setup
            var sut             = new SutBuilder <object>().Create();
            var expectedFactory = sut.Factory;
            // Exercise system
            var dummyPostprocessor = new DelegatingSpecifiedSpecimenCommand <object>();
            var result             = sut.WithPostprocessor(dummyPostprocessor);

            // Verify outcome
            Assert.Equal(expectedFactory, result.Factory);
            // Teardown
        }
Esempio n. 33
0
        public void Should_Format_Using_Default_Config()
        {
            // given

            // sut
            var sut = SutBuilder.Build();

            // when
            var result = sut.FormatMessage();

            // then
            Assert.That(result, Is.EqualTo("Hello world!"));
        }
Esempio n. 34
0
        public void FromQuadrupleInputFactoryReturnsCorrectResult()
        {
            // Fixture setup
            Func <Random, HttpStyleUriParser, LoaderOptimizationAttribute, Base64FormattingOptions, NetPipeStyleUriParser> expectedFactory = (x, y, z, æ) => new NetPipeStyleUriParser();
            var sut = new SutBuilder <NetPipeStyleUriParser>().Create();
            // Exercise system
            var result = sut.FromFactory(expectedFactory);
            // Verify outcome
            var resultingComposer = Assert.IsAssignableFrom <Composer <NetPipeStyleUriParser> >(result);
            var factory           = Assert.IsAssignableFrom <SpecimenFactory <Random, HttpStyleUriParser, LoaderOptimizationAttribute, Base64FormattingOptions, NetPipeStyleUriParser> >(resultingComposer.Factory);

            Assert.Equal(expectedFactory, factory.Factory);
            // Teardown
        }
Esempio n. 35
0
        public void WithoutReturnsCorrectResult()
        {
            // Fixture setup
            var expectedMember = typeof(PropertyHolder <string>).GetProperty("Property");
            var sut            = new SutBuilder <PropertyHolder <string> >().Create();
            // Exercise system
            var result = sut.Without(x => x.Property);
            // Verify outcome
            var resultingComposer = Assert.IsAssignableFrom <Composer <PropertyHolder <string> > >(result);
            var postprocessor     = resultingComposer.Postprocessors.OfType <SpecifiedNullCommand <PropertyHolder <string>, string> >().Single();

            Assert.Equal(expectedMember, postprocessor.Member);
            // Teardown
        }
Esempio n. 36
0
        public void WithAutoPropertiesReturnsCorrectResult()
        {
            // Fixture setup
            var sut = new SutBuilder <object>().WithAutoProperties(false).Create();
            // Exercise system
            var result = sut.WithAutoProperties();
            // Verify outcome
            var resultingComposer = Assert.IsAssignableFrom <Composer <object> >(result);

            Assert.Equal(sut.Factory, resultingComposer.Factory);
            Assert.True(sut.Postprocessors.SequenceEqual(resultingComposer.Postprocessors));
            Assert.True(resultingComposer.EnableAutoProperties);
            // Teardown
        }
Esempio n. 37
0
        public void DoReturnsCorrectResult()
        {
            // Fixture setup
            Action <long> expectedAction = s => { };
            var           sut            = new SutBuilder <long>().Create();
            // Exercise system
            var result = sut.Do(expectedAction);
            // Verify outcome
            var resultingComposer = Assert.IsAssignableFrom <Composer <long> >(result);
            var postprocessor     = resultingComposer.Postprocessors.OfType <UnspecifiedSpecimenCommand <long> >().Single();

            Assert.Equal(expectedAction, postprocessor.Action);
            // Teardown
        }
        public void CreateAuthorizationHeader()
        {
            const string Creds = "AccountKey:" + TestApiKey;
            var expected = $"Basic {Convert.ToBase64String(Encoding.ASCII.GetBytes(Creds))}";

            var sut = new SutBuilder<RequestHeaderFactory>().AddDependency(CreateSettings()).Build();

            using (var client = new HttpClient())
            {
                sut.SetHeaders(client.DefaultRequestHeaders);

                var authHeader = client.DefaultRequestHeaders.FirstOrDefault(h => h.Key == Constants.AuthorizationHeaderName);
                Assert.IsNotNull(authHeader);
                Assert.AreEqual(expected, authHeader.Value.First());
            }
        }
 public static TextAnalyticsService BuildSut(ITextAnalyticsRequestor requestor)
 {
     var sut = new SutBuilder<TextAnalyticsService>().AddDependency(requestor).AddDependency(new Settings()).AddDependency(new ErrorMessageGenerator()).Build();
     return sut;
 }
Esempio n. 40
0
 public void ThrowIfAnyConstructorArgumentIsNotAnInterface()
 {
     var sut = new SutBuilder<TestTypeWithNonInterfaceArgument>();
     AssertEx.Throws<InvalidOperationException>(() => sut.Build());
 }
 public void CreateAcceptHeader()
 {
     var expected = new MediaTypeWithQualityHeaderValue("application/json");
     var sut = new SutBuilder<RequestHeaderFactory>().Build();
     Assert.AreEqual(expected, sut.AcceptHeader());
 }
Esempio n. 42
0
        public void UseConstructorWithMostArguments()
        {
            var expected = new TestDependency { Identifier = "this is the one" };

            var sut = new SutBuilder<TestSut>().AddDependency(expected).Build();
            var result = sut.Dependency;

            Assert.AreEqual(expected.Identifier, result.Identifier);
        }