예제 #1
0
        public void GivenSpringfieldLocation_WhenAskingForMiniSizePizzaWithCrispyHam_ThenItShouldReturnCorrectValue()
        {
            // arrange
            Order order = new Order
            {
                Location = "Springfield",
                Products = new[]
                {
                    new ProductRequest
                    {
                        Name        = "Pizza",
                        Size        = "Mini",
                        Ingredients = new []
                        {
                            "Crispy Ham"
                        }
                    }
                }
            };

            // act
            Invoice invoice = order.Invoice();

            // assert
            Privateer       privateer = new Privateer();
            List <LineItem> lineItems = privateer.Field <List <LineItem> >(invoice, "_lineItems");

            lineItems.Should().HaveCount(1);
            privateer.Field <string>(lineItems[0], "_description").Should().Be("Mini Pizza with Crispy Ham");
            privateer.Field <string>(lineItems[0], "_price").Should().Be("$10.35");
        }
예제 #2
0
        public void GivenBricksburgLocation_WhenAskingForMiniSizePizza_ThenItShouldReturnCorrectValue()
        {
            // arrange
            Order order = new Order
            {
                Location = "Bricksburg",
                Products = new[]
                {
                    new ProductRequest
                    {
                        Name        = "Pizza",
                        Size        = "Personal",
                        Ingredients = new []
                        {
                            "Mushrooms"
                        }
                    }
                }
            };

            // act
            Invoice invoice = order.Invoice();

            // assert
            Privateer       privateer = new Privateer();
            List <LineItem> lineItems = privateer.Field <List <LineItem> >(invoice, "_lineItems");

            lineItems.Should().HaveCount(1);
            privateer.Field <string>(lineItems[0], "_description").Should().Be("Personal Pizza with Mushrooms");
            privateer.Field <string>(lineItems[0], "_price").Should().Be("17,33 &");
        }
예제 #3
0
        public void GivenProjectName_WhenAskingForBugs_ThenItShouldReturnBugs()
        {
            // arrange
            IBugsFactory fakeBugsFactory = new FakeBugsFactory(new Bugs(new List <Bug>
            {
                new Bug(1, "thing1"),
                new Bug(2, "thing2")
            }));

            BugController bugController = new Privateer().Object <BugController>(fakeBugsFactory);

            // act
            OkObjectResult okObjectResult = (OkObjectResult)bugController.Bugs("HankHill").Result;

            // assert
            okObjectResult.StatusCode.Should().Be(200);
            Bugs    bugs    = (Bugs)okObjectResult.Value;
            JObject jObject = JObject.Parse(JsonConvert.SerializeObject(bugs));

            jObject["bugs"].Should().HaveCount(2);
            jObject["bugs"][0]["id"].Value <int>().Should().Be(1);
            jObject["bugs"][0]["url"].Value <string>().Should().Be("thing1");
            jObject["bugs"][1]["id"].Value <int>().Should().Be(2);
            jObject["bugs"][1]["url"].Value <string>().Should().Be("thing2");
        }
예제 #4
0
        public void GivenEmptyProjectName_WhenCallingBuildsByDefinition_ShouldThrowException()
        {
            // arrange
            const string result         = "result";
            const string status         = "status";
            const int    definitionId   = 11;
            const string buildNumber    = "1.2.3.4";
            const string definitionName = "The Hill's CI";

            IBuildsFactory fakeBuildsFactory = new FakeBuildsFactory(1, new List <Build>
            {
                new Build(status, result, buildNumber, DateTime.Today, new Definition(definitionId, definitionName), new RequestedFor("Hank Hill", "http://image.shack.usa/hankhill"))
            });

            IPrivateer      privateer  = new Privateer();
            BuildController controller = privateer.Object <BuildController>(fakeBuildsFactory, new MemoryCache(new MemoryCacheOptions()));

            // act
            BadRequestResult badRequestResult = (BadRequestResult)controller.BuildsByDefinition(string.Empty, new List <int> {
                definitionId
            });

            // assert
            badRequestResult.Should().BeOfType <BadRequestResult>();
        }
예제 #5
0
        public void GivenPersonalSizePizza_WhenAskingForInvoice_ThenItShouldReturnCorrectInvoice()
        {
            // arrange
            Order order = new Order
            {
                Location = "Bedrock",
                Products = new []
                {
                    new ProductRequest
                    {
                        Name        = "Pizza",
                        Size        = "Personal",
                        Ingredients = new []
                        {
                            "Mushrooms",
                            "Pepperoni"
                        }
                    }
                }
            };

            // act
            Invoice invoice = order.Invoice();

            // assert
            Privateer       privateer = new Privateer();
            List <LineItem> lineItems = privateer.Field <List <LineItem> >(invoice, "_lineItems");

            lineItems.Should().HaveCount(1);
            privateer.Field <string>(lineItems[0], "_description").Should().Be("Personal Pizza with Mushrooms and Pepperoni");
            privateer.Field <string>(lineItems[0], "_price").Should().Be("$11.25");
        }
예제 #6
0
        public void WhenCallingBuilds_ShouldReturnBuilds()
        {
            // arrange
            const string result         = "result";
            const string status         = "status";
            const int    definitionId   = 11;
            const string buildNumber    = "1.2.3.4";
            const string definitionName = "The Hill's CI";

            IBuildsFactory fakeBuildsFactory = new FakeBuildsFactory(1, new List <Build>
            {
                new Build(status, result, buildNumber, DateTime.Today, new Definition(definitionId, definitionName), new RequestedFor("Hank Hill", "http://image.shack.usa/hankhill"))
            });

            BuildController controller = new Privateer().Object <BuildController>(fakeBuildsFactory, new MemoryCache(new MemoryCacheOptions()));

            // act
            OkObjectResult okObjectResult = (OkObjectResult)controller.Builds("StricklandPropane-CI");

            // assert
            okObjectResult.StatusCode.Should().Be(200);
            Builds  builds  = (Builds)okObjectResult.Value;
            JObject jObject = JObject.Parse(JsonConvert.SerializeObject(builds));

            jObject["count"].Value <int>().Should().Be(1);
            jObject["builds"].Should().HaveCount(1);

            jObject["builds"][0]["status"].Value <string>().Should().Be(status);
            jObject["builds"][0]["result"].Value <string>().Should().Be(result);
            jObject["builds"][0]["buildNumber"].Value <string>().Should().Be(buildNumber);

            jObject["builds"][0]["definition"]["id"].Value <int>().Should().Be(definitionId);
            jObject["builds"][0]["definition"]["name"].Value <string>().Should().Be(definitionName);
        }
예제 #7
0
        public void ShouldReturnBuildDefinitions()
        {
            // arrange
            const string project             = "StricklandPropaneTanks";
            const string buildDefinitionName = "StricklandPropaneSpatulas";
            const int    buildDefinitionId   = 234;

            IBuildDefinitionsFactory buildDefinitionsFactory = new FakeBuildDefinitionsFactory(1, new List <Definition> {
                new Definition(buildDefinitionId, buildDefinitionName)
            });
            BuildDefinitionController buildDefinitionController = new Privateer().Object <BuildDefinitionController>(buildDefinitionsFactory);

            // act
            OkObjectResult okObjectResult = (OkObjectResult)buildDefinitionController.BuildDefinitions(project);

            // assert
            okObjectResult.StatusCode.Should().Be(200);
            BuildDefinitions buildDefinitions = (BuildDefinitions)okObjectResult.Value;
            JObject          jObject          = JObject.Parse(JsonConvert.SerializeObject(buildDefinitions));

            jObject["count"].Value <int>().Should().Be(1);
            jObject["items"].Should().HaveCount(1);
            jObject["items"][0]["id"].Value <int>().Should().Be(buildDefinitionId);
            jObject["items"][0]["name"].Value <string>().Should().Be(buildDefinitionName);
        }
        public void ShouldReturnProjects()
        {
            // arrange
            IProjectsFactory fakeProjectsFactory = new FakeProjectsFactory(new Projects(2, new List <Project>
            {
                new Project("1", "thing1"),
                new Project("2", "thing2")
            }));
            ProjectController projectController = new Privateer().Object <ProjectController>(fakeProjectsFactory);

            // act
            OkObjectResult okObjectResult = (OkObjectResult)projectController.Projects();

            // assert
            okObjectResult.StatusCode.Should().Be(200);
            Projects projects = (Projects)okObjectResult.Value;
            JObject  jObject  = JObject.Parse(JsonConvert.SerializeObject(projects));

            jObject["count"].Value <int>().Should().Be(2);
            jObject["projects"].Should().HaveCount(2);
            jObject["projects"][0]["id"].Value <string>().Should().Be("1");
            jObject["projects"][0]["name"].Value <string>().Should().Be("thing1");
            jObject["projects"][1]["id"].Value <string>().Should().Be("2");
            jObject["projects"][1]["name"].Value <string>().Should().Be("thing2");
        }
예제 #9
0
        public void GivenAnySituation_WhenAskingToSend_ThenItShouldCallPostman()
        {
            // arrange
            FakePostman       fakePostman       = new FakePostman();
            ServiceBusMessage serviceBusMessage = new Privateer().Object <ServiceBusMessage>(fakePostman);

            // act
            Func <Task> func = async() => await serviceBusMessage.SendAsync();

            func.Invoke();

            // assert
            fakePostman.CallCount.Should().Be(1);
        }
예제 #10
0
        public void WhenCallingBuildsByDefinition_ShouldCacheAndReturnBuilds()
        {
            const string projectName          = "StricklandPropane-CI";
            const string result               = "result";
            const string status               = "status";
            const int    hanksDefinitionId    = 11;
            const string hanksBuildNumber     = "1.2.3.4";
            const string hanksDefinitionName  = "The Hill's CI";
            const int    peggysDefinitionId   = 12;
            const string peggysBuildNumber    = "1.0.0.1";
            const string peggysDefinitionName = "Peggy's Quilting Seminar CI";

            IBuildsFactory fakeBuildsFactory = new FakeBuildsFactory(2, new List <Build>
            {
                new Build(status, result, hanksBuildNumber, DateTime.Today, new Definition(hanksDefinitionId, hanksDefinitionName), new RequestedFor("Hank Hill", "http://image.shack.usa/hankhill")),
                new Build(status, result, peggysBuildNumber, DateTime.Today, new Definition(peggysDefinitionId, peggysDefinitionName), new RequestedFor("Peggy Hill", "http://image.shack.usa/peggyhill"))
            });

            MemoryCache     memoryCache = new MemoryCache(new MemoryCacheOptions());
            BuildController controller  = new Privateer().Object <BuildController>(fakeBuildsFactory, memoryCache);

            // act
            OkObjectResult okObjectResult = (OkObjectResult)controller.BuildsByDefinition(projectName, new List <int> {
                hanksDefinitionId, peggysDefinitionId
            });

            // assert
            okObjectResult.StatusCode.Should().Be(200);
            Builds  builds  = (Builds)okObjectResult.Value;
            JObject jObject = JObject.Parse(JsonConvert.SerializeObject(builds));

            jObject["count"].Value <int>().Should().Be(2);
            jObject["builds"].Should().HaveCount(2);

            jObject["builds"][0]["status"].Value <string>().Should().Be(status);
            jObject["builds"][0]["result"].Value <string>().Should().Be(result);
            jObject["builds"][0]["buildNumber"].Value <string>().Should().Be(hanksBuildNumber);
            jObject["builds"][0]["definition"]["id"].Value <int>().Should().Be(hanksDefinitionId);
            jObject["builds"][0]["definition"]["name"].Value <string>().Should().Be(hanksDefinitionName);

            jObject["builds"][1]["status"].Value <string>().Should().Be(status);
            jObject["builds"][1]["result"].Value <string>().Should().Be(result);
            jObject["builds"][1]["buildNumber"].Value <string>().Should().Be(peggysBuildNumber);
            jObject["builds"][1]["definition"]["id"].Value <int>().Should().Be(peggysDefinitionId);
            jObject["builds"][1]["definition"]["name"].Value <string>().Should().Be(peggysDefinitionName);

            memoryCache.TryGetValue($"{projectName}-{hanksDefinitionId}-{peggysDefinitionId}", out Builds cachedBuilds);
            cachedBuilds.Should().Be(builds);
        }
예제 #11
0
        public async Task GivenTopic_WhenAskingToSend_ThenItShouldCallNextStrategy()
        {
            // arrange
            FakeTopicClient    fakeTopicClient = new FakeTopicClient();
            Message            message         = new Message(Encoding.UTF8.GetBytes("{'Dammit':'Bobby!'}"));
            FakePostman        fakePostman     = new FakePostman();
            IServiceBusPostman postman         = new Privateer().Object <ServiceBusTopicPostman>(fakeTopicClient, message, fakePostman);

            // act
            async Task func() => await postman.SendAsync();

            await func();

            // assert
            fakePostman.CallCount.Should().Be(1);
        }
예제 #12
0
        public void GivenBricksburgLocationPersonalSizePizzaAndChangedIngredients_WhenAskingForInvoice_ThenItShouldReturnCorrectInvoice()
        {
            // arrange
            Order order = new Order
            {
                Location = "Bricksburg",
                Products = new []
                {
                    new ProductRequest
                    {
                        Name        = "Pizza",
                        Size        = "Personal",
                        Ingredients = new []
                        {
                            "Mushrooms",
                            "Pepperoni"
                        }
                    }
                }
            };

            order.Products = new[]
            {
                new ProductRequest
                {
                    Name        = "Pizza",
                    Size        = "Personal",
                    Ingredients = new[]
                    {
                        "Pepperoni"
                    }
                }
            };

            // act
            Invoice invoice = order.Invoice();

            // assert
            Privateer       privateer = new Privateer();
            List <LineItem> lineItems = privateer.Field <List <LineItem> >(invoice, "_lineItems");

            lineItems.Should().HaveCount(1);
            privateer.Field <string>(lineItems[0], "_description").Should().Be("Personal Pizza with Pepperoni");
            privateer.Field <string>(lineItems[0], "_price").Should().Be("18,11 &");

            string serializedInvoice = JsonConvert.SerializeObject(invoice);
        }
예제 #13
0
        public void GivenFulfilledNeed_WhenAskingForValue_ThenItShouldReturnCorrectValue()
        {
            // arrange
            FakeEventMessage fakeEventMessage     = new FakeEventMessage(new EventData(new ArraySegment <byte>()));
            FakeNeed         fakeNeed             = new FakeNeed();
            const string     stricklandPropaneLlc = "Strickland Propane, LLC";
            ExpandoObject    expected             = JsonConvert.DeserializeObject <ExpandoObject>($"{{'BusinessName':'{stricklandPropaneLlc}'}}");
            FakeResult       fakeResult           = new FakeResult(expected);
            INeedActivity    needActivity         = new Privateer().Object <GoogazonActivities.TopicNeedActivity.TopicNeedActivity>(fakeEventMessage, fakeNeed, fakeResult);

            // act
            dynamic actual = needActivity.ValueAsync().Result;

            // assert
            ((ExpandoObject)actual).Should().BeEquivalentTo(expected);
            ((string)actual.BusinessName).Should().Be(stricklandPropaneLlc);
        }
예제 #14
0
        public void GivenEmptyProjectName_ShouldThrowException()
        {
            string       project             = string.Empty;
            const string buildDefinitionName = "StricklandPropaneSpatulas";
            const int    buildDefinitionId   = 234;

            IBuildDefinitionsFactory buildDefinitionsFactory = new FakeBuildDefinitionsFactory(1, new List <Definition> {
                new Definition(buildDefinitionId, buildDefinitionName)
            });
            BuildDefinitionController buildDefinitionController = new Privateer().Object <BuildDefinitionController>(buildDefinitionsFactory);

            // act
            BadRequestResult badRequestResult = (BadRequestResult)buildDefinitionController.BuildDefinitions(project);

            // assert
            badRequestResult.StatusCode.Should().Be(400);
        }
예제 #15
0
        public void GivenEmptyProjectName_WhenAskingForBugs_ThenItShouldReturnBadRequest()
        {
            // arrange
            IBugsFactory fakeBugsFactory = new FakeBugsFactory(new Bugs(new List <Bug>
            {
                new Bug(1, "thing1"),
                new Bug(2, "thing2")
            }));

            BugController bugController = new Privateer().Object <BugController>(fakeBugsFactory);

            // act
            BadRequestResult badRequestResult = (BadRequestResult)bugController.Bugs(string.Empty).Result;

            // assert
            badRequestResult.StatusCode.Should().Be(400);
        }
        public async Task GivenPostmanChainThatShouldNotAllExecute_WhenAskingToSend_ThenItShouldExecuteCorrectPostmen()
        {
            // arrange
            Privateer          privateer       = new Privateer();
            FakePostman        nextFakePostman = new FakePostman(true);
            FakePostman        fakePostman     = new FakePostman(false, nextFakePostman);
            IServiceBusPostman postman         = privateer.Object <ServiceBusPostmen>(fakePostman);

            // act
            async Task func() => await postman.SendAsync();

            await func();

            // assert
            fakePostman.CallCount.Should().Be(0);
            nextFakePostman.CallCount.Should().Be(1);
        }
예제 #17
0
        public void GivenHalfSizeCalzoneWithChangedSizeAndIngredients_WhenAskingForInvoice_ThenItShouldReturnCorrectInvoice()
        {
            // arrange
            Order order = new Order
            {
                Location = "Bedrock",
                Products = new[]
                {
                    new ProductRequest
                    {
                        Name        = "Calzone",
                        Size        = "Half-Size",
                        Ingredients = new []
                        {
                            "Mushrooms",
                            "Pepperoni"
                        }
                    }
                }
            };

            order.Products = new[]
            {
                new ProductRequest
                {
                    Name        = "Calzone",
                    Size        = "Full",
                    Ingredients = new[]
                    {
                        "Pepperoni"
                    }
                }
            };

            // act
            Invoice invoice = order.Invoice();

            // assert
            Privateer       privateer = new Privateer();
            List <LineItem> lineItems = privateer.Field <List <LineItem> >(invoice, "_lineItems");

            lineItems.Should().HaveCount(1);
            privateer.Field <string>(lineItems[0], "_description").Should().Be("Full Calzone with Pepperoni");
            privateer.Field <string>(lineItems[0], "_price").Should().Be("$16.10");
        }
예제 #18
0
        public void GivenNeed_WhenAskingToExpressNeed_ThenItShouldCallExpressNeed()
        {
            // arrange
            FakeEventMessage fakeEventMessage     = new FakeEventMessage(new EventData(new ArraySegment <byte>()));
            FakeNeed         fakeNeed             = new FakeNeed();
            const string     stricklandPropaneLlc = "Strickland Propane, LLC";
            ExpandoObject    expected             = JsonConvert.DeserializeObject <ExpandoObject>($"{{'BusinessName':'{stricklandPropaneLlc}'}}");
            FakeResult       fakeResult           = new FakeResult(expected);
            INeedActivity    needActivity         = new Privateer().Object <GoogazonActivities.TopicNeedActivity.TopicNeedActivity>(fakeEventMessage, fakeNeed, fakeResult);

            // act
            Func <Task> func = async() => await needActivity.ExpressNeed();

            func.Invoke();

            // assert
            fakeNeed.CallCountSpy.Should().Be(1);
        }
        public async Task GivenEnrichedMessage_WhenAskingToSend_ThenItShouldOnlyCallQueueClient()
        {
            // arrange
            const string           messageBody     = "{'Dammit':'Bobby!','Results':'Dirty hippies.'}";
            Message                message         = new Message(Encoding.UTF8.GetBytes(messageBody));
            FakeQueueClient        fakeQueueClient = new FakeQueueClient();
            FakePostman            fakePostman     = new FakePostman();
            ServiceBusQueuePostman postman         = new Privateer().Object <ServiceBusQueuePostman>(fakeQueueClient, messageBody, message, fakePostman);

            // act
            async Task func() => await postman.SendAsync();

            await func();

            // assert
            fakeQueueClient.CallCount.Should().Be(1);
            fakePostman.CallCount.Should().Be(0);
        }