public async Task GetAllParts_WithDummyDataOrderByUsedCountDescending_ShouldReturnCorrectResults() { string errorMessagePrefix = "PartService GetAllParts() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); var criteria = "Used From Highest To Lowest"; List <PartServiceModel> actualResults = await _partService.GetAllParts(criteria).ToListAsync(); List <PartServiceModel> expectedResults = GetPartGetDummyData().To <PartServiceModel>().OrderByDescending(x => x.UsedCount).ToList(); for (int i = 0; i < expectedResults.Count; i++) { var expectedEntry = expectedResults[i]; var actualEntry = actualResults[i]; Assert.True(expectedEntry.Name == actualEntry.Name, errorMessagePrefix + " " + "Name is not returned properly."); Assert.True(expectedEntry.Price == actualEntry.Price, errorMessagePrefix + " " + "Price is not returned properly."); Assert.True(expectedEntry.UsedCount == actualEntry.UsedCount, errorMessagePrefix + " " + "UsedCount is not returned properly."); Assert.True(expectedEntry.Stock == actualEntry.Stock, errorMessagePrefix + " " + "Stock is not returned properly."); Assert.True(expectedEntry.AcquiredFrom.Name == actualEntry.AcquiredFrom.Name, errorMessagePrefix + " " + "AquiredFrom is not returned properly."); } }
public async Task CreatePart_WithCorrectData_ShouldSuccessfullyCreatePart() { string errorMessagePrefix = "PartService CreatePart() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); PartServiceModel part = new PartServiceModel() { Id = "P3", Name = "Break Pad For Trailer", Price = 140.15M, UsedCount = 0, Stock = 5, AcquiredFrom = new PartsProviderServiceModel() { Name = "Brembo" } }; bool actualResult = await _partService.Create(part); Assert.True(actualResult, errorMessagePrefix); }
public async Task GetAllUsers_WithDummyData_ShouldReturnCorrectResults() { string errorMessagePrefix = "UserService GetAllUsers() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _userService = new UserService(new FakeUserManager(), context); List <MDMSUserServiceModel> actualResults = await _userService.GetAllUsers().ToListAsync(); List <MDMSUserServiceModel> expectedResults = context.Users.To <MDMSUserServiceModel>().OrderBy(x => x.Name).ToList(); for (int i = 0; i < expectedResults.Count; i++) { var expectedEntry = expectedResults[i]; var actualEntry = actualResults[i]; Assert.True(actualEntry.Id == expectedEntry.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualEntry.Name == expectedEntry.Name, errorMessagePrefix + " " + "Name is not returned properly."); Assert.True(actualEntry.FirstName == expectedEntry.FirstName, errorMessagePrefix + " " + "FirstName is not returned properly."); Assert.True(actualEntry.LastName == expectedEntry.LastName, errorMessagePrefix + " " + "LastName is not returned properly."); Assert.True(actualEntry.Email == expectedEntry.Email, errorMessagePrefix + " " + "Email is not returned properly."); Assert.True(actualEntry.AdditionalOnHourPayment == expectedEntry.AdditionalOnHourPayment, errorMessagePrefix + " " + "AdditionalOnHourPayment is not returned properly."); Assert.True(actualEntry.BaseSalary == expectedEntry.BaseSalary, errorMessagePrefix + " " + "BaseSalary is not returned properly."); Assert.True(actualEntry.IsDeleted == expectedEntry.IsDeleted, errorMessagePrefix + " " + "IsDeleted is not returned properly."); Assert.True(actualEntry.IsRepairing == expectedEntry.IsRepairing, errorMessagePrefix + " " + "IsRepairing is not returned properly."); Assert.True(actualEntry.IsAuthorized == expectedEntry.IsAuthorized, errorMessagePrefix + " " + "IsAuthorized is not returned properly."); } }
public async Task GetVehicleByName_WithExistentName_ShouldReturnCorrectResults() { string errorMessagePrefix = "VehicleService GetVehicleByName() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _vehicleService = new VehicleService(context); VehicleServiceModel expectedData = context.Vehicles.SingleOrDefault(x => x.Name == "Mercedes_Actros_12345678901234567").To <VehicleServiceModel>(); VehicleServiceModel actualData = _vehicleService.GetVehicleByName("Mercedes_Actros_12345678901234567").Result; Assert.True(expectedData.Id == actualData.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(expectedData.Name == actualData.Name, errorMessagePrefix + " " + "Name is not returned properly."); Assert.True(expectedData.Price == actualData.Price, errorMessagePrefix + " " + "Price is not returned properly."); Assert.True(expectedData.Picture == actualData.Picture, errorMessagePrefix + " " + "Picture is not returned properly."); Assert.True(expectedData.Depreciation == actualData.Depreciation, errorMessagePrefix + "Depreciation" + "Depreciation is not returned properly."); Assert.True(expectedData.Model == actualData.Model, errorMessagePrefix + " " + "Model is not returned properly."); Assert.True(expectedData.Make == actualData.Make, errorMessagePrefix + " " + "Make is not returned properly."); Assert.True(expectedData.VSN == actualData.VSN, errorMessagePrefix + " " + "VSN is not returned properly."); Assert.True(expectedData.Mileage == actualData.Mileage, errorMessagePrefix + " " + "Mileage is not returned properly."); Assert.True(expectedData.RegistrationNumber == actualData.RegistrationNumber, errorMessagePrefix + " " + "RegistrationNumber is not returned properly."); Assert.True(expectedData.IsInRepair == actualData.IsInRepair, errorMessagePrefix + " " + "IsInRepair is not returned properly."); Assert.True(expectedData.AcquiredOn == actualData.AcquiredOn, errorMessagePrefix + " " + "AcquiredOn is not returned properly."); Assert.True(expectedData.ManufacturedOn == actualData.ManufacturedOn, errorMessagePrefix + " " + "ManufacturedOn is not returned properly."); Assert.True(expectedData.IsActive == actualData.IsActive, errorMessagePrefix + " " + "IsActive is not returned properly."); Assert.True(expectedData.IsDeleted == actualData.IsDeleted, errorMessagePrefix + " " + "IsDeleted is not returned properly."); Assert.True(expectedData.VehicleProvider.Name == actualData.VehicleProvider.Name, errorMessagePrefix + " " + "VehicleProviderName is not returned properly."); Assert.True(expectedData.VehicleType.Name == actualData.VehicleType.Name, errorMessagePrefix + " " + "VehicleTypeName is not returned properly."); }
public async Task GetCurrentUserByUsername_WithDummyData_ShouldReturnCorrectResults() { string errorMessagePrefix = "UserService GetCurrentUserByUsername() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _userService = new UserService(new FakeUserManager(), context); MDMSUserServiceModel actualResults = await _userService.GetCurrentUserByUsername("Pesho"); MDMSUserServiceModel expectedResults = context.Users.SingleOrDefault(x => x.UserName == "Pesho").To <MDMSUserServiceModel>(); Assert.True(actualResults.Id == expectedResults.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualResults.Name == expectedResults.Name, errorMessagePrefix + " " + "Name is not returned properly."); Assert.True(actualResults.FirstName == expectedResults.FirstName, errorMessagePrefix + " " + "FirstName is not returned properly."); Assert.True(actualResults.LastName == expectedResults.LastName, errorMessagePrefix + " " + "LastName is not returned properly."); Assert.True(actualResults.Email == expectedResults.Email, errorMessagePrefix + " " + "Email is not returned properly."); Assert.True(actualResults.AdditionalOnHourPayment == expectedResults.AdditionalOnHourPayment, errorMessagePrefix + " " + "AdditionalOnHourPayment is not returned properly."); Assert.True(actualResults.BaseSalary == expectedResults.BaseSalary, errorMessagePrefix + " " + "BaseSalary is not returned properly."); Assert.True(actualResults.IsDeleted == expectedResults.IsDeleted, errorMessagePrefix + " " + "IsDeleted is not returned properly."); Assert.True(actualResults.IsRepairing == expectedResults.IsRepairing, errorMessagePrefix + " " + "IsRepairing is not returned properly."); Assert.True(actualResults.IsAuthorized == expectedResults.IsAuthorized, errorMessagePrefix + " " + "IsAuthorized is not returned properly."); }
public async Task DeActivateUser_WithNonExistedId_ShouldThrowException() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _userService = new UserService(new FakeUserManager(), context); await Assert.ThrowsAsync <NullReferenceException>(() => _userService.DeActivateUser("idzzzzzz")); }
public async Task AddStockPart_WithNonExistingName_ShouldThrowException() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); await Assert.ThrowsAsync <NullReferenceException>(() => _partService.AddStock("name", 5)); }
public async Task GetPartByName_WithNonExistentName_ShouldThrowException() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); await Assert.ThrowsAsync <ArgumentNullException>(() => _partService.GetPartByName("Name")); }
public async Task DeleteVehicle_WithNonExistedVehicleId_ShouldThrowExceptionDeletePart() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _vehicleService = new VehicleService(context); await Assert.ThrowsAsync <NullReferenceException>(() => _vehicleService.DeleteVehicle("idzzzzzz")); }
public async Task EditVehicle_WithNonExistedVehicle_ShouldThrowException() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _vehicleService = new VehicleService(context); await Assert.ThrowsAsync <NullReferenceException>(() => _vehicleService.Edit(new VehicleServiceModel())); }
public async Task DeletePart_WithNonExistedPartNameData_ShouldThrowExceptionDeletePart() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); await Assert.ThrowsAsync <NullReferenceException>(() => _partService.DeletePart("name")); }
public async Task GetCurrentUserByUsername_WithNonExistentName_ShouldThrowException() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _userService = new UserService(new FakeUserManager(), context); await Assert.ThrowsAsync <ArgumentNullException>(() => _userService.GetCurrentUserByUsername("Name")); }
public async Task GetReportDetails_WithNonExistentName_ShouldSuccessThrowException() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedReportData(context); _reportService = new ReportService(context); await Assert.ThrowsAsync <NullReferenceException>(() => _reportService.GetReportDetails("Name")); }
public async Task GetAllReports_WithCorrectData_ShouldSuccessfullyGetAllReport() { string errorMessagePrefix = "ReportService GetAllReports() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedReportData(context); _reportService = new ReportService(context); List <ReportServiceModel> actualReportDataList = _reportService.GetAllReports().ToList(); List <ReportServiceModel> expectedReportDataList = context.Reports.OrderBy(x => x.Name).To <ReportServiceModel>().ToList(); for (int j = 0; j < actualReportDataList.Count; j++) { var actualReportData = actualReportDataList[j]; var expectedReportData = expectedReportDataList[j]; var actualVehicles = actualReportDataList[j].VehiclesInReport.ToList(); var expectedVehicles = expectedReportDataList[j].VehiclesInReport.ToList(); Assert.True(actualReportData.Id == expectedReportData.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualReportData.Name == expectedReportData.Name, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualReportData.StartYear == expectedReportData.StartYear, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualReportData.EndYear == expectedReportData.EndYear, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualReportData.StartMonth == expectedReportData.StartMonth, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(actualReportData.EndMonth == expectedReportData.EndMonth, errorMessagePrefix + " " + "Id is not returned properly."); for (int i = 0; i < actualReportData.VehiclesInReport.Count; i++) { var actualData = actualVehicles[i]; var expectedData = expectedVehicles[i]; Assert.True(expectedData.Id == actualData.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(expectedData.Name == actualData.Name, errorMessagePrefix + " " + "Name is not returned properly."); Assert.True(expectedData.Price == actualData.Price, errorMessagePrefix + " " + "Price is not returned properly."); Assert.True(expectedData.Picture == actualData.Picture, errorMessagePrefix + " " + "Picture is not returned properly."); Assert.True(expectedData.Depreciation == actualData.Depreciation, errorMessagePrefix + "Depreciation" + "Depreciation is not returned properly."); Assert.True(expectedData.Model == actualData.Model, errorMessagePrefix + " " + "Model is not returned properly."); Assert.True(expectedData.Make == actualData.Make, errorMessagePrefix + " " + "Make is not returned properly."); Assert.True(expectedData.VSN == actualData.VSN, errorMessagePrefix + " " + "VSN is not returned properly."); Assert.True(expectedData.Mileage == actualData.Mileage, errorMessagePrefix + " " + "Mileage is not returned properly."); Assert.True(expectedData.RegistrationNumber == actualData.RegistrationNumber, errorMessagePrefix + " " + "RegistrationNumber is not returned properly."); Assert.True(expectedData.IsInRepair == actualData.IsInRepair, errorMessagePrefix + " " + "IsInRepair is not returned properly."); Assert.True(expectedData.AcquiredOn == actualData.AcquiredOn, errorMessagePrefix + " " + "AcquiredOn is not returned properly."); Assert.True(expectedData.ManufacturedOn == actualData.ManufacturedOn, errorMessagePrefix + " " + "ManufacturedOn is not returned properly."); Assert.True(expectedData.IsActive == actualData.IsActive, errorMessagePrefix + " " + "IsActive is not returned properly."); Assert.True(expectedData.IsDeleted == actualData.IsDeleted, errorMessagePrefix + " " + "IsDeleted is not returned properly."); Assert.True(expectedData.VehicleProvider.Name == actualData.VehicleProvider.Name, errorMessagePrefix + " " + "VehicleProviderName is not returned properly."); Assert.True(expectedData.VehicleType.Name == actualData.VehicleType.Name, errorMessagePrefix + " " + "VehicleTypeName is not returned properly."); } } }
public async Task GetAllUsers_WithZeroData_ShouldReturnEmptyResults() { string errorMessagePrefix = "UserService GetAllUsers() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); _userService = new UserService(new FakeUserManager(), context); List <MDMSUserServiceModel> actualResults = await _userService.GetAllUsers().ToListAsync(); Assert.True(actualResults.Count == 0, errorMessagePrefix); }
public async Task GetAllPartProviders_WithZeroData_ShouldReturnEmptyResults() { string errorMessagePrefix = "PartService GetAllPartProviders() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); _partService = new PartService(context); List <PartsProviderServiceModel> actualResults = await _partService.GetAllPartProviders().ToListAsync(); Assert.True(actualResults.Count == 0, errorMessagePrefix); }
public async Task GetVehicleByName_WithNonExistentName_ShouldReturnNull() { string errorMessagePrefix = "VehicleService GetVehicleByName() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _vehicleService = new VehicleService(context); Assert.True(_vehicleService.GetVehicleByName("Name").Result == null, errorMessagePrefix); }
public async Task EditPart_WithWrongData_ShouldThrowException() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); await Assert.ThrowsAsync <ArgumentNullException>(() => _partService.EditPart( context.Parts.SingleOrDefault(x => x.Name == "Break Pad For Trailer") .To <PartServiceModel>())); }
public async Task DeletePart_WithCorrectData_ShouldDeletePart() { string errorMessagePrefix = "PartService DeletePart() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); bool actualResult = await _partService.DeletePart("Break Pad For Truck"); Assert.True(actualResult, errorMessagePrefix); }
public async Task DeleteReport_WithCorrectData_ShouldSuccessfullyDeleteReport() { string errorMessagePrefix = "ReportService DeleteReport() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedReportData(context); _reportService = new ReportService(context); bool actualResult = await _reportService.DeleteReport("Custom_2019_1_2019_12"); Assert.True(actualResult, errorMessagePrefix); }
public async Task AddStockPart_WithCorrectData_ShouldAddStock() { string errorMessagePrefix = "PartService AddStock() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); bool actualResult = await _partService.AddStock("Blot 10.5x2", 5); Assert.True(actualResult, errorMessagePrefix); }
public async Task GetAllReports_WithNonExistentName_ShouldReturnEmptyCollection() { string errorMessagePrefix = "ReportService GetAllReports() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedReportData(context); _reportService = new ReportService(context); List <ReportServiceModel> actualResults = await _reportService.GetAllReports().ToListAsync(); Assert.True(actualResults.Count == 0, errorMessagePrefix); }
public async Task RestoreUser_WithCorrectData_ShouldRestoreUser() { string errorMessagePrefix = "UserService RestoreUser() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _userService = new UserService(new FakeUserManager(), context); bool actualResult = await _userService.RestoreUser("U4"); Assert.True(actualResult, errorMessagePrefix); }
public async Task EditPayment_WithWrongId_ShouldFailToAddSalary() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _userService = new UserService(new FakeUserManager(), context); MDMSUserServiceModel user = await _userService.GetCurrentUserByUsername("Pesho"); user.Id = "NoId"; user.AdditionalOnHourPayment = 60; user.BaseSalary = 4000; await Assert.ThrowsAsync <NullReferenceException>(() => _userService.EditPayment(user)); }
public async Task CreateVehicleType_WithDublicateName_ShouldFailToCreateVehicleType() { string errorMessagePrefix = "VehicleService CreateVehicleType() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _vehicleService = new VehicleService(context); bool actualResult = await _vehicleService.CreateVehicleType(new VehicleTypeServiceModel() { Name = "Truck" }); Assert.False(actualResult, errorMessagePrefix); }
public async Task CreateVehicleProvider_WithCorrectData_ShouldSuccessfullyVehicleProvider() { string errorMessagePrefix = "VehicleService CreateVehicleProvider() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _vehicleService = new VehicleService(context); bool actualResult = await _vehicleService.CreateVehicleProvider(new VehicleProviderServiceModel() { Name = "BMW" }); Assert.True(actualResult, errorMessagePrefix); }
public async Task CreatePartProvider_WithDublicateName_ShouldFailToCreatePartProvider() { string errorMessagePrefix = "PartService CreatePartProvider() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); bool actualResult = await _partService.CreatePartProvider(new PartsProviderServiceModel() { Name = "Brembo" }); Assert.False(actualResult, errorMessagePrefix); }
public async Task EditPayment_WithCorrectData_ShouldSuccessfullyEditPayment() { string errorMessagePrefix = "UserService EditPayment() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _userService = new UserService(new FakeUserManager(), context); MDMSUserServiceModel user = await _userService.GetCurrentUserByUsername("Pesho"); user.AdditionalOnHourPayment = 60; user.BaseSalary = 4000; bool actualResult = await _userService.EditPayment(user); Assert.True(actualResult, errorMessagePrefix); }
public async Task CreatePart_NotExistentPartProvider_ShouldThrowException() { var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); await Assert.ThrowsAsync <ArgumentNullException>(() => _partService.Create(new PartServiceModel() { Id = "P3", Name = "Break Pad For Trailer", Price = 140.15M, UsedCount = 0, Stock = 5, AcquiredFrom = context.Parts.SingleOrDefault(x => x.Name == "Trembol").To <PartsProviderServiceModel>() })); }
public async Task GetPartByName_WithExistentName_ShouldReturnCorrectResults() { string errorMessagePrefix = "PartService GetPartByName() method does not work properly."; var context = MdmsDbContextInMemoryFactory.InitializeContext(); await SeedData(context); _partService = new PartService(context); PartServiceModel expectedData = context.Parts.SingleOrDefault(x => x.Name == "Blot 10.5x2").To <PartServiceModel>(); PartServiceModel actualData = await _partService.GetPartByName("Blot 10.5x2"); Assert.True(expectedData.Name == actualData.Name, errorMessagePrefix + " " + "Name is not returned properly."); Assert.True(expectedData.Price == actualData.Price, errorMessagePrefix + " " + "Price is not returned properly."); Assert.True(expectedData.UsedCount == actualData.UsedCount, errorMessagePrefix + " " + "UsedCount is not returned properly."); Assert.True(expectedData.Stock == actualData.Stock, errorMessagePrefix + " " + "Stock is not returned properly."); Assert.True(expectedData.AcquiredFrom.Name == actualData.AcquiredFrom.Name, errorMessagePrefix + " " + "AquiredFrom is not returned properly."); }