Ejemplo n.º 1
0
        public void Routes_require_established_depots_at_origin_and_destination(string missingDepot)
        {
            var expectedOriginBody       = "Kerbin";
            var expectedOriginBiome      = "LaunchPad";
            var expectedDestinationBody  = "Mun";
            var expectedDestinationBiome = "East Crater";
            var expectedPayload          = 5;
            var persistenceLayer         = new TestPersister();

            switch (missingDepot)
            {
            case "origin":
                persistenceLayer.CreateDepot(expectedDestinationBody, expectedDestinationBiome);
                break;

            case "destination":
                persistenceLayer.CreateDepot(expectedOriginBody, expectedOriginBiome);
                break;
            }

            Assert.Throws <DepotDoesNotExistException>(() =>
            {
                persistenceLayer.CreateRoute(
                    expectedOriginBody,
                    expectedOriginBiome,
                    expectedDestinationBody,
                    expectedDestinationBiome,
                    expectedPayload);
            });
        }
Ejemplo n.º 2
0
        public void Routes_should_be_one_way()
        {
            var expectedOriginBody       = "Kerbin";
            var expectedOriginBiome      = "LaunchPad";
            var expectedDestinationBody  = "Mun";
            var expectedDestinationBiome = "East Crater";
            var expectedPayload          = 5;
            var persistenceLayer         = new TestPersister();
            var expectedOriginDepot      = persistenceLayer.CreateDepot(expectedOriginBody, expectedOriginBiome);
            var expectedDestinationDepot = persistenceLayer.CreateDepot(expectedDestinationBody, expectedDestinationBiome);

            persistenceLayer.CreateRoute(
                expectedOriginBody,
                expectedOriginBiome,
                expectedDestinationBody,
                expectedDestinationBiome,
                expectedPayload);

            var reverseRoute = persistenceLayer.GetRoute(
                expectedDestinationBody,
                expectedDestinationBiome,
                expectedOriginBody,
                expectedOriginBiome);

            Assert.Null(reverseRoute);
        }
Ejemplo n.º 3
0
        public void Routes_should_be_persisted()
        {
            var configNode       = new ConfigNode();
            var persister        = new TestPersister();
            var originBody       = "Mun";
            var originBiome      = "East Crater";
            var destinationBody  = "Minmus";
            var destinationBiome = "Greater Flats";
            var payload          = 12;
            var resourceName1    = "SpecializedParts";
            var quantity1        = 8;
            var resourceName2    = "ColonySupplies";
            var quantity2        = 4;

            var originDepot = persister.CreateDepot(originBody, originBiome);

            persister.CreateDepot(destinationBody, destinationBiome);
            var startingResources = new Dictionary <string, int>
            {
                { resourceName1, quantity1 },
                { resourceName2, quantity2 }
            };

            originDepot.NegotiateProvider(startingResources);
            var route = persister.CreateRoute(originBody, originBiome, destinationBody, destinationBiome, payload);

            route.AddResource(resourceName1, quantity1);
            route.AddResource(resourceName2, quantity2);

            persister.OnSave(configNode);

            Assert.True(configNode.HasNode(ScenarioPersister.ROUTES_NODE_NAME));
            var wolfNode = configNode.GetNode(ScenarioPersister.ROUTES_NODE_NAME);

            Assert.True(wolfNode.HasData);
            var routeNodes = wolfNode.GetNodes();
            var routeNode  = routeNodes.First();

            Assert.True(routeNode.HasValue("OriginBody"));
            Assert.True(routeNode.HasValue("OriginBiome"));
            Assert.True(routeNode.HasValue("DestinationBody"));
            Assert.True(routeNode.HasValue("DestinationBiome"));
            Assert.True(routeNode.HasValue("Payload"));
            var originBodyValue       = routeNode.GetValue("OriginBody");
            var originBiomeValue      = routeNode.GetValue("OriginBiome");
            var destinationBodyValue  = routeNode.GetValue("DestinationBody");
            var destinationBiomeValue = routeNode.GetValue("DestinationBiome");
            var payloadValue          = int.Parse(routeNode.GetValue("Payload"));

            Assert.Equal(originBody, originBodyValue);
            Assert.Equal(originBiome, originBiomeValue);
            Assert.Equal(destinationBody, destinationBodyValue);
            Assert.Equal(destinationBiome, destinationBiomeValue);
            Assert.Equal(payload, payloadValue);
            Assert.True(routeNode.HasNode("RESOURCE"));
            var resourceNodes = routeNode.GetNodes();

            Assert.Equal(2, resourceNodes.Length);
            var resourceNode = resourceNodes[0];

            Assert.True(resourceNode.HasValue("ResourceName"));
            Assert.True(resourceNode.HasValue("Quantity"));
            var nodeResourceName  = resourceNode.GetValue("ResourceName");
            var nodeQuantityValue = int.Parse(resourceNode.GetValue("Quantity"));

            Assert.Equal(resourceName1, nodeResourceName);
            Assert.Equal(quantity1, nodeQuantityValue);
        }