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 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]); } }