public void Ensure_FleetService_LoadFleet_Formats_ReadFile_Into_List_Of_Lines_If_Seperator_Is_CaridgeReturn() { var repo = A.Fake<IFileRepository>(); var logger = A.Fake<ILogger>(); string host = "1,M5,0,1,1,0,1" ; var expectedResult = new HostDto(){ Id= 1, Instance="M1", N = 5, FilledSlots = 3 }; var hostValidation = new HostValidation(logger); var result = hostValidation.ValidateAndCreateHost(host); Assert.AreEqual(expectedResult.FilledSlots, result.FilledSlots); }
public FleetResult LoadFleet(FleetRequest request) { Guardian.ArgumentNotNull(request, "request"); Guardian.ArgumentNotNull(request.FileLocation, "request.FileLocation"); var result = new FleetResult(); string[] hostEnteries = new string[0]; var fleetStateFile = Repository.LoadFile(request.FileLocation); if (fleetStateFile.IsNullOrEmpty()) { Logger.Error(ErrorMessages.FileNotFound); result.Notifications.Add(ErrorMessages.FileNotFound); } else { if (fleetStateFile.Contains("{0}{1}".FormatLiteralArguments(Constants.CaridgeReturn, Constants.NewLine))) { hostEnteries = fleetStateFile.Split("{0}{1}".FormatLiteralArguments(Constants.CaridgeReturn, Constants.NewLine).ToCharArray()); } else if (fleetStateFile.Contains(Constants.CaridgeReturn)) { hostEnteries = fleetStateFile.Split(Constants.CaridgeReturn.ToCharArray()); } else { result.Notifications.Add(ErrorMessages.IncorrectFfileState); } if (!result.Notifications.HasErrors) { hostEnteries = hostEnteries.Where(x => x.IsNotNullOrEmpty()).ToArray(); if (hostEnteries.Length == 0) { result.Notifications.Add(ErrorMessages.IncorrectFfileState); } else { var hostValidation = new HostValidation(Logger); var createdHosts = new List <HostDto>(); foreach (var host in hostEnteries) { var createdHost = hostValidation.CreateHost(host); if (createdHost.IsNotNull()) { createdHosts.Add(createdHost); } } result.Hosts = createdHosts; } } } return(result); }