public KeyValuePair <string, string> CalculateNumberOfResupplyStopsNeeded(StarshipEntity starship, int distance) { var totalHoursOfConsumables = _calculationService.GetConsumablesInHours(starship.GetConsumables()); var totalHoursOfTravel = _calculationService.GetTotalHoursToTravel(distance, starship.GetMGLT()); if (totalHoursOfConsumables == null || totalHoursOfTravel == null) { return(new KeyValuePair <string, string>(starship.GetName(), "unknown")); } else { var numberOfStopsRequired = totalHoursOfTravel.Value / totalHoursOfConsumables.Value; return(new KeyValuePair <string, string>(starship.GetName(), numberOfStopsRequired.ToString())); } }
public void GetNameTest() { //// Arrange string name = "test1"; string mglt = "100"; string consumables = "1 day"; var starshipEntity = new StarshipEntity(name, mglt, consumables); //// Act var starshipEntityName = starshipEntity.GetName(); //// Assert Assert.AreEqual(name, starshipEntityName); }
public void StarshipEntityTest_ConsumablesIsNull() { //// Arrange string name = "test1"; string mglt = "100"; string consumables = null; //// Act var starshipEntity = new StarshipEntity(name, mglt, consumables); //// Assert Assert.AreEqual(name, starshipEntity.GetName()); Assert.AreEqual(string.Empty, starshipEntity.GetConsumables()); Assert.AreEqual(Convert.ToInt32(mglt), starshipEntity.GetMGLT()); }
public void StarshipEntityTest_NameIsUnkown(string value) { //// Arrange string name = value; string mglt = "100"; string consumables = "1 day"; //// Act var starshipEntity = new StarshipEntity(name, mglt, consumables); //// Assert Assert.AreEqual(string.Empty, starshipEntity.GetName()); Assert.AreEqual(consumables, starshipEntity.GetConsumables()); Assert.AreEqual(Convert.ToInt32(mglt), starshipEntity.GetMGLT()); }
public void CalculateNumberOfResupplyStopsNeededTest_TotalHoursToTravelReturnsNull() { ////Arrange _calculationServiceMock.Setup(x => x.GetConsumablesInHours(It.IsAny <string>())) .Returns(10) .Verifiable(); _calculationServiceMock.Setup(x => x.GetTotalHoursToTravel(It.IsAny <int>(), It.IsAny <int?>())) .Returns <int?>(null) .Verifiable(); StarshipEntity starshipEntity = new StarshipEntity("Test1", string.Empty, string.Empty); ////Act var response = _starshipResupplyCalculation.CalculateNumberOfResupplyStopsNeeded(starshipEntity, 1000); ////Assert Assert.IsNotNull(response); Assert.AreEqual(starshipEntity.GetName(), response.Key); Assert.AreEqual("unknown", response.Value); }