public async Task CreateAsync_Should_Create_Successfully() { //Arrange var context = Context; IOfficeBusiness officeBusiness = new OfficeBusiness(context, _mapper, _cache, _busMock.Object); CreateOfficeCommand command = new CreateOfficeCommand { Location = "Amsterdam", OpenTime = DateTime.Now.TimeOfDay, CloseTime = DateTime.Now.AddHours(1).TimeOfDay }; //Act await officeBusiness.CreateAsync(command); var addedOffice = await context.Offices .FirstOrDefaultAsync(); //Assert Assert.NotNull(addedOffice); Assert.Equal("Amsterdam", addedOffice.Location); }
// GET: Load public ActionResult Index() { var Loadboard = new LoadboardViewModel(); Loadboard.StatusSelector = SelectListHelper.Generic(LoadBusiness.GetLoadStatuses(_user)); //retrieve save searches Loadboard.SavedSearches = _user.SavedSearches.Where(i => i.Category == Globals.SearchCategories.Loadboard).ToList(); //retrieve save loadboard settings var LoadboardSettings = _user.Settings.FirstOrDefault(i => i.SettingName == "Loadboard"); if (LoadboardSettings != null) { Loadboard.Settings = LoadboardSettings.SettingValue; } using (var OfficeBusiness = new OfficeBusiness(_applicationServicesSetup, _user)) { Loadboard.OfficeGroups = OfficeBusiness.GetUserGroupsByOffice(_user.OfficeId, new[] { Globals.Related.OfficeGroup.Members }); //if just an agent, only show the groups you are apart of. if (_user.IsAgent() && !_user.IsEmployee()) { Loadboard.OfficeGroups = Loadboard.OfficeGroups.Where(i => i.Members.Select(u => u.Id == _user.Id).Any()).ToList(); } } return(View(Loadboard)); }
public async Task CreateAsync_Should_Publish_Event_Successfully() { //Arrange var context = Context; var harness = new InMemoryTestHarness(); await harness.Start(); IOfficeBusiness officeBusiness = new OfficeBusiness(context, _mapper, _cache, harness.Bus); CreateOfficeCommand command = new CreateOfficeCommand { Location = "Amsterdam", OpenTime = DateTime.Now.TimeOfDay, CloseTime = DateTime.Now.AddHours(1).TimeOfDay }; //Act await officeBusiness.CreateAsync(command); //Assert try { Assert.True(await harness.Published.Any <OfficeCreated>()); } finally { await harness.Stop(); } }
public async Task ExistsAsync_Should_Return_True_If_Exists_In_Database() { //Arrange var context = Context; IOfficeBusiness officeBusiness = new OfficeBusiness(context, _mapper, _cache, _busMock.Object); Office office = new Office { Id = Guid.NewGuid(), OpenTime = DateTime.Now.TimeOfDay, CloseTime = DateTime.Now.AddHours(1).TimeOfDay, Location = "Amsterdam" }; await context.Offices.AddAsync(office); await context.SaveChangesAsync(); //Act var exists = await officeBusiness.ExistsAsync(office.Id); //Assert Assert.True(exists); }
public async Task GetAsync_Should_Get_Data_From_Database_For_First_Time_Sucessfully() { //Arrange var context = Context; IOfficeBusiness officeBusiness = new OfficeBusiness(context, _mapper, _cache, _busMock.Object); await context.Offices.AddAsync(new Office { Id = Guid.NewGuid(), OpenTime = DateTime.Now.TimeOfDay, CloseTime = DateTime.Now.AddHours(1).TimeOfDay, Location = "Amsterdam" }); await context.SaveChangesAsync(); //Act var offices = await officeBusiness.GetAsync(); //Assert Assert.NotNull(offices); Assert.IsType <List <OfficeViewModel> >(offices); Assert.Single(offices); }
/// <summary> /// Requests all products available in the office and prints them. /// </summary> private void ViewAllProducts() { Console.Clear(); Console.WriteLine(new string('-', 40)); Console.WriteLine(new string(' ', 14) + "ALL PRODUCTS"); Console.WriteLine(new string('-', 40) + '\n'); string name; while (true) { Console.Write("Office name: "); name = Console.ReadLine(); Console.WriteLine(); if (OfficeBusiness.OfficeExists(name)) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid office name!"); Console.WriteLine(new string('-', 26) + '\n'); } Console.WriteLine(OfficeBusiness.AllProductsAvailableInOffice(OfficeBusiness.GetID(name))); Console.ReadKey(); }
/// <summary> /// Requests the information of all the offices in a given city. /// </summary> private void ViewAllOfficesInCity() { Console.Clear(); Console.WriteLine(new string('-', 41)); Console.WriteLine(new string(' ', 15) + "ALL OFFICES"); Console.WriteLine(new string('-', 41) + '\n'); string city; while (true) { Console.Write("City: "); city = Console.ReadLine(); Console.WriteLine(); if (!(city.Length < 1) && OfficeBusiness.CityExists(city)) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid city!"); Console.WriteLine(new string('-', 26) + '\n'); } foreach (Office office in OfficeBusiness.AllOfficesInACity(city)) { Console.WriteLine($"{office.Name} - {office.City}"); } Console.ReadKey(); }
/// <summary> /// Requests the information of all the offices. /// </summary> private void ViewAllOffices() { foreach (Office office in OfficeBusiness.GetAllOffices()) { Console.WriteLine($"{office.Name} - {office.City}"); } Console.ReadKey(); }
// GET: Dashboard public ActionResult Index() { //if user does not have permission to view the dashboard using (var OfficeBusiness = new OfficeBusiness(_applicationServicesSetup, _user)) { ViewBag.AccountingGroup = OfficeBusiness.GetAccountingGroupByOffice(_user.OfficeId); } this.SetSelectors(); return(View()); }
public async Task CreateAsync_Should_Throw_Exception_IfModelNull() { //Arrange IOfficeBusiness officeBusiness = new OfficeBusiness(Context, _mapper, _cache, _busMock.Object); async Task func() => await officeBusiness.CreateAsync(null); //Act & Assert await Assert.ThrowsAsync <ArgumentNullException>(func); }
public async Task ExistsAsync_Should_Return_False_If_Not_Exists_In_Database() { //Arrange var context = Context; IOfficeBusiness officeBusiness = new OfficeBusiness(context, _mapper, _cache, _busMock.Object); //Act var exists = await officeBusiness.ExistsAsync(Guid.NewGuid()); //Assert Assert.False(exists); }
public async Task AvailableOfficesAsync_Should_Return_Available_Office_By_Current_User_Is_Location() { //Arrange var context = Context; IOfficeBusiness officeBusiness = new OfficeBusiness(context, _mapper, _cache, _busMock.Object); Office amsterdamOffice = new Office { Id = Guid.NewGuid(), OpenTime = new TimeSpan(8, 0, 0), CloseTime = new TimeSpan(17, 30, 0), Location = "Amsterdam" }; Office berlinOffice = new Office { Id = Guid.NewGuid(), OpenTime = new TimeSpan(8, 0, 0), CloseTime = new TimeSpan(20, 0, 0), Location = "Berlin" }; await context.Offices.AddAsync(amsterdamOffice); await context.Offices.AddAsync(berlinOffice); await context.SaveChangesAsync(); CheckOfficeAvailailityCommand commandShouldCoverBoth = new CheckOfficeAvailailityCommand { //Should cover both offices Location = "Amsterdam", StartTime = new TimeSpan(8, 0, 0), EndTime = new TimeSpan(16, 0, 0) }; //Act var amsterdamOfficeId = await officeBusiness.AvailableOfficesAsync(commandShouldCoverBoth); //Assert Assert.Equal(amsterdamOffice.Id, amsterdamOfficeId); }
private void SetSelectors() { using (OfficeBusiness officeBusiness = new OfficeBusiness(_applicationServicesSetup, _user)) { if (_user.IsAdmin()) { ViewBag.OfficeSelector = Helpers.SelectListHelper.Offices(officeBusiness.ActiveOffices(), "-- Select an Office --"); } else if (_user.IsManager() || _user.IsEmployee()) { ViewBag.GroupsSelector = Helpers.SelectListHelper.Groups(officeBusiness.GetUserGroupsByOffice(_user.OfficeId), "-- Select a Group --"); } } using (UserBusiness userBusiness = new UserBusiness(_applicationServicesSetup, _user)) { ViewBag.UserSelector = Helpers.SelectListHelper.Users(userBusiness.GetAllUsers(), "-- Select a User --"); } }
public async Task GetAsync_Should_Get_Data_From_Cache_Successfully() { //Arrange var context = Context; IOfficeBusiness officeBusiness = new OfficeBusiness(context, _mapper, _cache, _busMock.Object); Office office = new Office { Id = Guid.NewGuid(), OpenTime = DateTime.Now.TimeOfDay, CloseTime = DateTime.Now.AddHours(1).TimeOfDay, Location = "Amsterdam" }; await context.Offices.AddAsync(office); await context.SaveChangesAsync(); //Act await officeBusiness.GetAsync(); context.Offices.Remove(office); await context.SaveChangesAsync(); var officesFromCache = await officeBusiness.GetAsync(); //Assert Assert.NotNull(officesFromCache); Assert.Single(officesFromCache); }
/// <summary> /// Requests a new office to be created. /// </summary> private void CreateOffice() { string name, city, address, phone; Console.Clear(); Console.WriteLine(new string('-', 40)); Console.WriteLine(new string(' ', 14) + "Create Office"); Console.WriteLine(new string('-', 40) + '\n'); while (true) { Console.Write("Office name: "); name = Console.ReadLine(); Console.WriteLine(); if (!OfficeBusiness.OfficeExists(name)) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid office name!"); Console.WriteLine(new string('-', 26) + '\n'); } while (true) { Console.Write("City: "); city = Console.ReadLine(); Console.WriteLine(); if (city.Length > 2) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid city name!"); Console.WriteLine(new string('-', 26) + '\n'); } while (true) { Console.Write("Address: "); address = Console.ReadLine(); Console.WriteLine(); if (address.Length > 6) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid address!"); Console.WriteLine(new string('-', 26) + '\n'); } while (true) { Console.Write("Phone: "); phone = Console.ReadLine(); Console.WriteLine(); if (phone.Length > 9) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid phone number!"); Console.WriteLine(new string('-', 26) + '\n'); } OfficeBusiness.CreateOffice(name, city, address, phone); }
/// <summary> /// Request a shipping from one office to another. /// </summary> private void ShipProduct() { string officeNameFrom, officeNameTo, productName; Console.Clear(); Console.WriteLine(new string('-', 40)); Console.WriteLine(new string(' ', 14) + "SHIP PRODUCT"); Console.WriteLine(new string('-', 40)); Console.WriteLine(); while (true) { Console.Write("Office name(from): "); officeNameFrom = Console.ReadLine(); Console.WriteLine(); if (OfficeBusiness.OfficeExists(officeNameFrom)) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid office name!"); Console.WriteLine(new string('-', 26) + '\n'); } while (true) { Console.Write("Office name(to): "); officeNameTo = Console.ReadLine(); Console.WriteLine(); if (OfficeBusiness.OfficeExists(officeNameTo)) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid office name!"); Console.WriteLine(new string('-', 26) + '\n'); } while (true) { Console.Write("Product name: "); productName = Console.ReadLine(); Console.WriteLine(); if (OfficeBusiness.ProductAvailable(OfficeBusiness.GetID(officeNameFrom), ProductBusiness.GetID(productName))) { break; } Console.WriteLine(new string('-', 27)); Console.WriteLine("Please enter a valid price!"); Console.WriteLine(new string('-', 27) + '\n'); } OfficeBusiness.TransferProduct(OfficeBusiness.GetID(officeNameFrom), OfficeBusiness.GetID(officeNameTo), ProductBusiness.GetID(productName)); }
/// <summary> /// Request a product to be loaded to an office. /// </summary> private void LoadProduct() { string officeName, distributorName, productName; int stock; Console.Clear(); Console.WriteLine(new string('-', 40)); Console.WriteLine(new string(' ', 14) + "LOAD PRODUCT"); Console.WriteLine(new string('-', 40) + '\n'); while (true) { Console.Write("Office name: "); officeName = Console.ReadLine(); Console.WriteLine(); if (OfficeBusiness.OfficeExists(officeName)) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid office name!"); Console.WriteLine(new string('-', 26) + '\n'); } while (true) { Console.Write("Distributor name: "); distributorName = Console.ReadLine(); Console.WriteLine(); if (!(distributorName.Length < 1) && DistributorBusiness.DistributorExists(DistributorBusiness.GetID(distributorName))) { break; } Console.WriteLine(new string('-', 26)); Console.WriteLine("Please enter a valid name!"); Console.WriteLine(new string('-', 26) + '\n'); } while (true) { Console.Write("Product name: "); productName = Console.ReadLine(); Console.WriteLine(); if (DistributorBusiness.CheckForProduct(DistributorBusiness.GetID(distributorName), ProductBusiness.GetID(productName))) { break; } Console.WriteLine(new string('-', 27)); Console.WriteLine("Please enter a valid price!"); Console.WriteLine(new string('-', 27) + '\n'); } while (true) { Console.Write("Stock: "); stock = int.Parse(Console.ReadLine()); Console.WriteLine(); if (!(stock < 0)) { break; } Console.WriteLine(new string('-', 27)); Console.WriteLine("Please enter a valid stock!"); Console.WriteLine(new string('-', 27) + '\n'); } OfficeBusiness.LoadProduct(OfficeBusiness.GetID(officeName), DistributorBusiness.GetProduct(DistributorBusiness.GetID(distributorName), ProductBusiness.GetID(productName)), stock); }