public void Origin_depot_must_have_requsted_resource() { 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); var route = new TestRoute( expectedOriginBody, expectedOriginBiome, expectedDestinationBody, expectedDestinationBiome, expectedPayload, persistenceLayer); var expectedResource = "Ore"; var requestedQuantity = 5; var result = route.AddResource(expectedResource, requestedQuantity); Assert.IsType <FailedNegotiationResult>(result); Assert.False(route.Resources.ContainsKey(expectedResource)); }
public void Can_assign_resources_to_a_route() { 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); var route = new TestRoute( expectedOriginBody, expectedOriginBiome, expectedDestinationBody, expectedDestinationBiome, expectedPayload, persistenceLayer); var expectedResource = "Ore"; var expectedQuantity = 5; var startingResources = new Dictionary <string, int> { { expectedResource, expectedQuantity } }; expectedOriginDepot.NegotiateProvider(startingResources); var result = route.AddResource(expectedResource, expectedQuantity); Assert.IsType <OkNegotiationResult>(result); Assert.True(route.Resources.ContainsKey(expectedResource)); Assert.Equal(expectedQuantity, route.Resources[expectedResource]); }
public void Route_payload_should_be_obeyed() { 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); var route = new TestRoute( expectedOriginBody, expectedOriginBiome, expectedDestinationBody, expectedDestinationBiome, expectedPayload, persistenceLayer); var expectedResource = "Ore"; var expectedQuantity = 5; var startingResources = new Dictionary <string, int> { { expectedResource, expectedQuantity } }; expectedOriginDepot.NegotiateProvider(startingResources); var result = route.AddResource(expectedResource, expectedQuantity + 1); Assert.IsType <InsufficientPayloadNegotiationResult>(result); Assert.False(route.Resources.ContainsKey(expectedResource)); }
public void Should_not_allow_changes_if_destination_dependencies_would_break() { 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); var route = new TestRoute( expectedOriginBody, expectedOriginBiome, expectedDestinationBody, expectedDestinationBiome, expectedPayload, persistenceLayer); var expectedResource = "Ore"; var providedQuantity = 5; var usedQuantity = 3; var startingResources = new Dictionary <string, int> { { expectedResource, providedQuantity } }; expectedOriginDepot.NegotiateProvider(startingResources); var addResult = route.AddResource(expectedResource, providedQuantity); var consumedResources = new Dictionary <string, int> { { expectedResource, usedQuantity } }; expectedDestinationDepot.NegotiateConsumer(consumedResources); var removeResult = route.RemoveResource(expectedResource, providedQuantity); Assert.IsType <OkNegotiationResult>(addResult); Assert.IsType <BrokenNegotiationResult>(removeResult); Assert.True(route.Resources.ContainsKey(expectedResource)); Assert.Equal(providedQuantity, route.Resources[expectedResource]); var depotResources = expectedDestinationDepot.GetResources() .Where(r => r.ResourceName == expectedResource) .FirstOrDefault(); Assert.Equal(usedQuantity, depotResources.Outgoing); }
public void Origin_depot_availability_should_be_obeyed() { 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); var route = new TestRoute( expectedOriginBody, expectedOriginBiome, expectedDestinationBody, expectedDestinationBiome, expectedPayload, persistenceLayer); var expectedResource = "Ore"; var requestedQuantity = 5; var availableQuantity = 4; var startingResources = new Dictionary <string, int> { { expectedResource, availableQuantity } }; expectedOriginDepot.NegotiateProvider(startingResources); var result = route.AddResource(expectedResource, requestedQuantity); Assert.IsType <FailedNegotiationResult>(result); Assert.False(route.Resources.ContainsKey(expectedResource)); var depotResource = expectedOriginDepot.GetResources() .Where(r => r.ResourceName == expectedResource) .FirstOrDefault(); Assert.Equal(availableQuantity, depotResource.Incoming); Assert.Equal(0, depotResource.Outgoing); Assert.Equal(availableQuantity, depotResource.Available); }
public void Can_remove_route_resources(int startingPayload, int amountToRemove) { var expectedOriginBody = "Kerbin"; var expectedOriginBiome = "LaunchPad"; var expectedDestinationBody = "Mun"; var expectedDestinationBiome = "East Crater"; var persistenceLayer = new TestPersister(); var expectedOriginDepot = persistenceLayer.CreateDepot(expectedOriginBody, expectedOriginBiome); var expectedDestinationDepot = persistenceLayer.CreateDepot(expectedDestinationBody, expectedDestinationBiome); var route = new TestRoute( expectedOriginBody, expectedOriginBiome, expectedDestinationBody, expectedDestinationBiome, startingPayload, persistenceLayer); var expectedResource = "Ore"; var startingResources = new Dictionary <string, int> { { expectedResource, startingPayload } }; expectedOriginDepot.NegotiateProvider(startingResources); var addResult = route.AddResource(expectedResource, startingPayload); var removeResult = route.RemoveResource(expectedResource, amountToRemove); Assert.IsType <OkNegotiationResult>(addResult); Assert.IsType <OkNegotiationResult>(removeResult); if (startingPayload == amountToRemove) { Assert.False(route.Resources.ContainsKey(expectedResource)); } else { Assert.True(route.Resources.ContainsKey(expectedResource)); Assert.Equal(startingPayload - amountToRemove, route.Resources[expectedResource]); } }
public void Route_resources_should_be_added_to_destination_depot() { 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); var route = new TestRoute( expectedOriginBody, expectedOriginBiome, expectedDestinationBody, expectedDestinationBiome, expectedPayload, persistenceLayer); var expectedResource = "Ore"; var expectedQuantity = 5; var startingResources = new Dictionary <string, int> { { expectedResource, expectedQuantity } }; expectedOriginDepot.NegotiateProvider(startingResources); var result = route.AddResource(expectedResource, expectedQuantity); Assert.IsType <OkNegotiationResult>(result); var depotResources = expectedDestinationDepot.GetResources(); var resource = depotResources .Where(r => r.ResourceName == expectedResource) .FirstOrDefault(); Assert.Equal(expectedQuantity, resource.Incoming); Assert.Equal(0, resource.Outgoing); Assert.Equal(expectedQuantity, resource.Available); }