Exemplo n.º 1
0
        public async void CreateAsync(UserCreateDTO user, String azureUId, ResponseLogic expected)
        {
            var existingUser = new User()
            {
                Id = 1, Firstname = "IAlready", Surname = "Exist", Mail = "*****@*****.**", AzureUId = "existingAuzreUId"
            };
            var existingLocation = new Location()
            {
                Id = 1, City = "Sydney", Country = "Australia"
            };

            userRepository     = new UserRepository(setupContextForIntegrationTests());
            skillRepository    = new SkillRepository(context);
            projectRepository  = new ProjectRepository(context);
            locationRepository = new LocationRepository(context);

            var locationLogic = new LocationLogic(locationRepository, userRepository, projectRepository);

            context.Users.Add(existingUser);
            context.Locations.Add(existingLocation);
            context.SaveChanges();

            //SanityCheck
            Assert.Equal(1, await context.Users.CountAsync());
            Assert.Equal(existingUser, await context.Users.FirstAsync());
            Assert.Equal(1, await context.Locations.CountAsync());
            Assert.Equal(existingLocation, await context.Locations.FirstAsync());

            using (var logic = new UserLogic(userRepository, skillLogicMock.Object, sparkLogicMock.Object, locationLogic))
            {
                var result = await logic.CreateAsync(user, azureUId);

                Assert.Equal(expected, result);
            }
        }
Exemplo n.º 2
0
        private async void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            string address = SuggestBox.Text;

            if (!CrossGeolocator.Current.IsListening)
            {
                IGeolocator locator = await LocationLogic.GetGeolocator(PermissionsLogic.IsLocationAccessPermitted);
            }
            var location = await LocationLogic.GetLocation();

            string PositionNow = LocationLogic.LocationStringBuilder(location);
            var    places      = await GoogleAPIRequest.GetPlaces(PositionNow, address);

            // Only get results when it was a user typing,
            // otherwise assume the value got filled in by TextMemberPath
            // or the handler for SuggestionChosen.
            if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
            {
                //Set the ItemsSource to be your filtered dataset
                //sender.ItemsSource = dataset;
                var           PlacesList = places.predictions.ToList();
                List <string> AddresList = new List <string>();
                PlacesList.ForEach(l => AddresList.Add(l.description));
                SuggestBox.ItemsSource = AddresList;
            }
        }
Exemplo n.º 3
0
        public async void UpdateAsync_GivenErrorUpdating_ReturnsERROR_UPDATING()
        {
            var locationToUpdate = new LocationDTO
            {
                Id      = 1,
                City    = "Sydne",
                Country = "Australia"
            };

            var locationToUpdateWithChanges = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToUpdateWithChanges.Id)).ReturnsAsync(locationToUpdate);
            locationRepositoryMock.Setup(c => c.UpdateAsync(locationToUpdateWithChanges)).ReturnsAsync(false);

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.UpdateAsync(locationToUpdateWithChanges);

                Assert.Equal(ResponseLogic.ERROR_UPDATING, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToUpdateWithChanges.Id));
                locationRepositoryMock.Verify(c => c.UpdateAsync(locationToUpdateWithChanges));
            }
        }
Exemplo n.º 4
0
 public void SetCharacterData(AuthorizedCharacterData data)
 {
     Assets               = new AssetsLogic(client, config, data);
     Bookmarks            = new BookmarksLogic(client, config, data);
     Calendar             = new CalendarLogic(client, config, data);
     Character            = new CharacterLogic(client, config, data);
     Clones               = new ClonesLogic(client, config, data);
     Contacts             = new ContactsLogic(client, config, data);
     Contracts            = new ContractsLogic(client, config, data);
     Corporation          = new CorporationLogic(client, config, data);
     FactionWarfare       = new FactionWarfareLogic(client, config, data);
     Fittings             = new FittingsLogic(client, config, data);
     Fleets               = new FleetsLogic(client, config, data);
     Industry             = new IndustryLogic(client, config, data);
     Killmails            = new KillmailsLogic(client, config, data);
     Location             = new LocationLogic(client, config, data);
     Loyalty              = new LoyaltyLogic(client, config, data);
     Mail                 = new MailLogic(client, config, data);
     Market               = new MarketLogic(client, config, data);
     Opportunities        = new OpportunitiesLogic(client, config, data);
     PlanetaryInteraction = new PlanetaryInteractionLogic(client, config, data);
     Search               = new SearchLogic(client, config, data);
     Skills               = new SkillsLogic(client, config, data);
     UserInterface        = new UserInterfaceLogic(client, config, data);
     Wallet               = new WalletLogic(client, config, data);
     Universe             = new UniverseLogic(client, config, data);
 }
Exemplo n.º 5
0
        public async void RemoveWithObjectAsync_GivenLocationExistsAndInNoProjectsOrUsers_ReturnsSuccess()
        {
            var locationToDelete = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToDelete.Id)).ReturnsAsync(locationToDelete);
            locationRepositoryMock.Setup(c => c.DeleteAsync(locationToDelete.Id)).ReturnsAsync(true);
            projectRepositoryMock.Setup(p => p.ReadAsync()).ReturnsAsync(new ProjectSummaryDTO[] { });
            userRepositoryMock.Setup(u => u.ReadAsync()).ReturnsAsync(new UserDTO[] { });

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.RemoveWithObjectAsync(locationToDelete);

                Assert.Equal(ResponseLogic.SUCCESS, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToDelete.Id));
                locationRepositoryMock.Verify(c => c.DeleteAsync(locationToDelete.Id));
                projectRepositoryMock.Verify(p => p.ReadAsync());
                userRepositoryMock.Verify(u => u.ReadAsync());
            }
        }
Exemplo n.º 6
0
        public async void FindAsyncWithCity_GivenLocationsExist_ReturnsEnumerableLocations()
        {
            var locationsToReturn = new LocationDTO[]
            {
                new LocationDTO {
                    Id = 1, City = "Sydney", Country = "Australia"
                },
                new LocationDTO {
                    Id = 2, City = "Melbourne", Country = "Australia"
                },
                new LocationDTO {
                    Id = 3, City = "Brisbane", Country = "Australia"
                }
            };

            locationRepositoryMock.Setup(c => c.FindWildcardAsync("e")).ReturnsAsync(locationsToReturn);

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var results = await logic.FindAsync("e");

                Assert.Equal(locationsToReturn, results);
                locationRepositoryMock.Verify(c => c.FindWildcardAsync("e"));
            }
        }
Exemplo n.º 7
0
        public static List <SelectListItem> PopulateLocationSelectListItem()
        {
            try
            {
                LocationLogic   locationLogic = new LocationLogic();
                List <LOCATION> locations     = locationLogic.GetEntitiesBy(p => p.Active);
                if (locations == null || locations.Count <= 0)
                {
                    return(new List <SelectListItem>());
                }

                List <SelectListItem> selectlist = new List <SelectListItem>();

                SelectListItem list = new SelectListItem();
                list.Value = "";
                list.Text  = Select;
                selectlist.Add(list);

                foreach (LOCATION location in locations)
                {
                    SelectListItem selectList = new SelectListItem();
                    selectList.Value = location.Id.ToString();
                    selectList.Text  = location.Name;

                    selectlist.Add(selectList);
                }

                return(selectlist);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 8
0
        public async void RemoveWithObjectAsync_GivenLocationExistsInMoreThanOneProjectAndUser_ReturnsSuccess()
        {
            var locationToDelete = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            var projectsArray = new ProjectSummaryDTO[]
            {
                new ProjectSummaryDTO {
                    Title = "Project1", LocationId = locationToDelete.Id
                },
                new ProjectSummaryDTO {
                    Title = "Project2", LocationId = locationToDelete.Id
                }
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToDelete.Id)).ReturnsAsync(locationToDelete);
            projectRepositoryMock.Setup(p => p.ReadAsync()).ReturnsAsync(projectsArray);
            userRepositoryMock.Setup(u => u.ReadAsync()).ReturnsAsync(new UserDTO[] { });

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.RemoveWithObjectAsync(locationToDelete);

                Assert.Equal(ResponseLogic.SUCCESS, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToDelete.Id));
                locationRepositoryMock.Verify(c => c.DeleteAsync(It.IsAny <int>()), Times.Never());
                projectRepositoryMock.Verify(p => p.ReadAsync());
                userRepositoryMock.Verify(u => u.ReadAsync());
            }
        }
Exemplo n.º 9
0
 void Start()
 {
     //Creates tiles in scene
     CreateMap(_location);
     CreateVentilation(nameof(ventilationFloor),
                       LocationLogic.CreatePairsForVentilation(_ventilationEntrances, maximumNumberOfPaths, turnProbability));
 }
Exemplo n.º 10
0
        public async void DeleteAsync_GivenCategoryExistsAndInNoProjects_ReturnsSuccess()
        {
            var locationToDelete = new Location
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepository = new LocationRepository(setupContextForIntegrationTests());

            context.Locations.Add(locationToDelete);
            context.SaveChanges();

            //Sanity Check
            Assert.NotNull(context.Locations.Find(locationToDelete.Id));
            Assert.Empty(await context.Projects.ToArrayAsync());

            using (var logic = new LocationLogic(locationRepository, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.DeleteAsync(locationToDelete.Id);

                Assert.Equal(ResponseLogic.SUCCESS, response);
            }
        }
Exemplo n.º 11
0
        public async void RemoveWithObjectAsync_GivenDatabaseError_ReturnsERROR_DELETING()
        {
            var locationToDelete = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToDelete.Id)).ReturnsAsync(locationToDelete);
            locationRepositoryMock.Setup(c => c.DeleteAsync(locationToDelete.Id)).ReturnsAsync(false);
            projectRepositoryMock.Setup(p => p.ReadAsync()).ReturnsAsync(new ProjectSummaryDTO[] { });
            userRepositoryMock.Setup(u => u.ReadAsync()).ReturnsAsync(new UserDTO[] { });

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.RemoveWithObjectAsync(locationToDelete);

                Assert.Equal(ResponseLogic.ERROR_DELETING, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToDelete.Id));
                locationRepositoryMock.Verify(c => c.DeleteAsync(locationToDelete.Id));
                projectRepositoryMock.Verify(p => p.ReadAsync());
                userRepositoryMock.Verify(u => u.ReadAsync());
            }
        }
Exemplo n.º 12
0
        public async void CreateAsync_GivenLocationyExists_ReturnsSUCCESS()
        {
            var locationToCreate = new LocationCreateDTO
            {
                City    = "Sydney",
                Country = "Australia"
            };

            var existingLocation = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToCreate.City, locationToCreate.Country)).ReturnsAsync(existingLocation);

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.CreateAsync(locationToCreate);

                Assert.Equal(ResponseLogic.SUCCESS, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToCreate.City, locationToCreate.Country));
                locationRepositoryMock.Verify(c => c.CreateAsync(It.IsAny <LocationCreateDTO>()), Times.Never());
            }
        }
Exemplo n.º 13
0
        public async void UpdateAsync_GivenLocationExists_ReturnsSuccess()
        {
            var locationToUpdate = new LocationDTO
            {
                Id      = 1,
                City    = "Sydne",
                Country = "Australia"
            };

            var locationToUpdateWithChanges = new LocationDTO
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync(locationToUpdateWithChanges.Id)).ReturnsAsync(locationToUpdate);
            locationRepositoryMock.Setup(c => c.UpdateAsync(locationToUpdateWithChanges)).ReturnsAsync(true);

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.UpdateAsync(locationToUpdateWithChanges);

                Assert.Equal(ResponseLogic.SUCCESS, response);
                locationRepositoryMock.Verify(c => c.FindAsync(locationToUpdateWithChanges.Id));
                locationRepositoryMock.Verify(c => c.UpdateAsync(locationToUpdateWithChanges));
            }
        }
        /// <summary>
        /// Display a list of all registered locations to the console
        /// </summary>
        private static void DisplayLocations()
        {
            LocationLogic locationLogic = new LocationLogic();
            Packet        LocationList  = locationLogic.GetAllLocationsPacket();

            Console.WriteLine(LocationList.Text);
        }
        public void RestockWithInvalidLocation()
        {
            LocationLogic locationLogic       = new LocationLogic();
            var           response            = locationLogic.RestockInventory("", "product", 10);
            string        expectedFailMessage = "Please enter a valid location name.";

            Assert.Equal(response.Text, expectedFailMessage);
        }
        public void RestockWithNegativeInventory()
        {
            LocationLogic locationLogic       = new LocationLogic();
            var           response            = locationLogic.RestockInventory("location", "product", -10);
            string        expectedFailMessage = "Please enter a postive number to increase the inventory by.";

            Assert.Equal(response.Text, expectedFailMessage);
        }
Exemplo n.º 17
0
        public ActionResult LocaleDelete(int localeID)
        {
            int areaid = (from f in db.Locales
                          where f.Id == localeID
                          select f).FirstOrDefault().AreaId;

            LocationLogic.AdminLocaleHide(localeID);
            return(RedirectToAction("AreaDetail", new { areaID = areaid }));
        }
Exemplo n.º 18
0
        public static void PromptForCustomerPurchase()
        {
            // Display a list of customers and prompt user to select which customer will
            // be making a purchase
            CustomerLogic customerLogic    = new CustomerLogic();
            var           customerResponse = customerLogic.GetCustomerList();

            Console.WriteLine(customerResponse.Text);

            Console.WriteLine("From the list above choose the customer who will be making the purchase:");
            string usernameInput = Console.ReadLine();

            Console.WriteLine("\n");


            // Display list of locations that the selected customer will be making a purchase from
            // prompt user to choose which location to make a purchase from
            LocationLogic locationLogic     = new LocationLogic();
            var           locationsResponse = locationLogic.GetAllLocationsPacket();

            Console.WriteLine(locationsResponse.Text + "\n");

            Console.WriteLine("From the list above choose a location that you wish to make a purchase from:");
            string locationNameInput = Console.ReadLine();

            Console.WriteLine("\n");

            // Display the location's inventory, revealing a list of products and the
            // quantity the current location posseses of those products
            // prompt user which product will be purchased and the amount to purchase
            ProductInventoryLogic pIL    = new ProductInventoryLogic();
            var productInventoryResponse = pIL.RetrieveInventoryPacketByLocationName(locationNameInput);

            Console.WriteLine(productInventoryResponse.Text + "\n");

            Console.WriteLine("Please select a product from the list above to be purchsed:");
            string productNameInput = Console.ReadLine();

            Console.WriteLine("Select the amount:");
            string quantityInput = Console.ReadLine();


            // validate the quantity entered is a number
            int  quantityParse;
            bool canConvertQauntity = Int32.TryParse(quantityInput, out quantityParse);

            if (!canConvertQauntity)
            {
                Console.WriteLine("Invalid input - quantity must be a number");
                return;
            }
            // perform the purchase and display the results to the console
            var purchaseResponse = customerLogic.MakePurchase(usernameInput, locationNameInput, productNameInput, quantityParse);

            Console.WriteLine(purchaseResponse.Text);
        }
Exemplo n.º 19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        public EsiClient(IOptions <EsiConfig> _config)
        {
            config = _config.Value;
            client = new HttpClient(new HttpClientHandler
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            });

            // Enforce user agent value
            if (string.IsNullOrEmpty(config.UserAgent))
            {
                throw new ArgumentException("For your protection, please provide an X-User-Agent value. This can be your character name and/or project name. CCP will be more likely to contact you rather than just cut off access to ESI if you provide something that can identify you within the New Eden galaxy.");
            }
            else
            {
                client.DefaultRequestHeaders.Add("X-User-Agent", config.UserAgent);
            }

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
            client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));

            SSO                  = new SsoLogic(client, config);
            Alliance             = new AllianceLogic(client, config);
            Assets               = new AssetsLogic(client, config);
            Bookmarks            = new BookmarksLogic(client, config);
            Calendar             = new CalendarLogic(client, config);
            Character            = new CharacterLogic(client, config);
            Clones               = new ClonesLogic(client, config);
            Contacts             = new ContactsLogic(client, config);
            Contracts            = new ContractsLogic(client, config);
            Corporation          = new CorporationLogic(client, config);
            Dogma                = new DogmaLogic(client, config);
            FactionWarfare       = new FactionWarfareLogic(client, config);
            Fittings             = new FittingsLogic(client, config);
            Fleets               = new FleetsLogic(client, config);
            Incursions           = new IncursionsLogic(client, config);
            Industry             = new IndustryLogic(client, config);
            Insurance            = new InsuranceLogic(client, config);
            Killmails            = new KillmailsLogic(client, config);
            Location             = new LocationLogic(client, config);
            Loyalty              = new LoyaltyLogic(client, config);
            Mail                 = new MailLogic(client, config);
            Market               = new MarketLogic(client, config);
            Opportunities        = new OpportunitiesLogic(client, config);
            PlanetaryInteraction = new PlanetaryInteractionLogic(client, config);
            Routes               = new RoutesLogic(client, config);
            Search               = new SearchLogic(client, config);
            Skills               = new SkillsLogic(client, config);
            Sovereignty          = new SovereigntyLogic(client, config);
            Status               = new StatusLogic(client, config);
            Universe             = new UniverseLogic(client, config);
            UserInterface        = new UserInterfaceLogic(client, config);
            Wallet               = new WalletLogic(client, config);
            Wars                 = new WarsLogic(client, config);
        }
Exemplo n.º 20
0
        public ReservationSystemForm(User user)
        {
            InitializeComponent();
            _user         = user;
            _eventRepo    = new EventLogic(new EventOracleContext());
            _guestRepo    = new GuestLogic(new GuestOracleContext());
            _locationRepo = new LocationLogic(new LocationOracleContext());

            _events = _eventRepo.GetAllEvents();

            cmbEvents.DataSource    = _events;
            cmbEvents.SelectedIndex = 0;
        }
Exemplo n.º 21
0
        private async void GetAllDistricts()
        {
            var districts = await LocationLogic.FetchAllDistrictsAsync();

            foreach (var district in districts)
            {
                cbxDistricts.Items.Add(district);
            }

            if (districts.Count > 0)
            {
                cbxDistricts.SelectedIndex = 0;
            }
        }
Exemplo n.º 22
0
        private async void LoadAllProvinces()
        {
            DataSource = await LocationLogic.FetchAllProvincesAsync();

            foreach (var province in DataSource)
            {
                cbxProvinces.Items.Add(province);
            }

            if (DataSource.Count > 0)
            {
                cbxProvinces.SelectedIndex = 0;
            }
        }
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            await PermissionsLogic.GetPermissions();

            IGeolocator locator = await LocationLogic.GetGeolocator(PermissionsLogic.IsLocationAccessPermitted);

            Position position = await locator.GetPositionAsync();

            Positions.Add(position);
            LocationsMap.IsShowingUser = true;
            MoveMap(position);
            CrossGeolocator.Current.PositionChanged += Locator_PositionChanged;
        }
        private static void DisplayLocationsInventory()
        {
            // List all locations
            DisplayLocations();

            // Prompt user to enter the name of the location they want to
            // view the order history on
            Console.WriteLine("Please enter the name of the location from the list above to view their inventory");

            string        locationNameInput = Console.ReadLine();
            LocationLogic locationLogic     = new LocationLogic();
            Packet        response          = locationLogic.GetLocationInventoryByNamePacket(locationNameInput);

            Console.WriteLine(response.Text);
        }
Exemplo n.º 25
0
        public ActionResult ManageLocation()
        {
            _viewModel     = new SetupViewModel();
            _locationLogic = new LocationLogic();
            try
            {
                _viewModel.LocationList = _locationLogic.GetEntitiesBy(c => c.Active);
            }
            catch (Exception)
            {
                throw;
            }

            return(View(_viewModel));
        }
        /// <summary>
        /// Prompts the user to enter the name of a location from a provided list.
        /// Display the order history of the chosen location.
        /// </summary>
        private static void DisplayLocationsOrderHistory()
        {
            // List all locations
            DisplayLocations();

            // Prompt user to enter the name of the location they want to
            // view the order history on
            Console.WriteLine("Please enter the name of the location from the list above to view their order history");

            string        locationNameInput         = Console.ReadLine();
            LocationLogic locationLogic             = new LocationLogic();
            var           fetchOrderHistoryResponse = locationLogic.GetLocationOrderHistoryPacket(locationNameInput);

            // Display the order history for that location
            Console.WriteLine(fetchOrderHistoryResponse.Text);
        }
Exemplo n.º 27
0
        public async void GetAsync_GivenExistingLocationId_ReturnsLocation()
        {
            var locationToReturn = new LocationDTO {
                Id = 3, City = "Brisbane", Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync(3)).ReturnsAsync(locationToReturn);

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var result = await logic.GetAsync(3);

                Assert.Equal(locationToReturn, result);
                locationRepositoryMock.Verify(c => c.FindAsync(3));
            }
        }
Exemplo n.º 28
0
        public async void FindExactAsync_GivenLocationExists_ReturnsLocation()
        {
            var locationToReturn = new LocationDTO {
                Id = 1, City = "Sydney", Country = "Australia"
            };

            locationRepositoryMock.Setup(c => c.FindAsync("Sydney", "Australia")).ReturnsAsync(locationToReturn);

            using (var logic = new LocationLogic(locationRepositoryMock.Object, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var result = await logic.FindExactAsync("Sydney", "Australia");

                Assert.Equal(locationToReturn, result);
                locationRepositoryMock.Verify(c => c.FindAsync("Sydney", "Australia"));
            }
        }
Exemplo n.º 29
0
        public JsonResult SaveLocation(int locationId, string name, string description, decimal longitude, decimal latitude)
        {
            JsonResponseModel result = new JsonResponseModel();

            try
            {
                if (locationId > 0 && !string.IsNullOrEmpty(name) && longitude > 0M && latitude > 0M)
                {
                    _locationLogic = new LocationLogic();
                    LOCATION location = _locationLogic.GetEntityBy(c => c.Id == locationId);

                    LOCATION existingLocation = _locationLogic.GetEntitiesBy(c => c.Latitude == latitude && c.Longitude == longitude && c.Id != locationId).LastOrDefault();
                    if (existingLocation == null)
                    {
                        if (location != null)
                        {
                            location.Name        = name;
                            location.Description = description;
                            location.Longitude   = longitude;
                            location.Latitude    = latitude;

                            _locationLogic.Modify(location);
                        }

                        result.IsError = false;
                        result.Message = "Operation Successful!";
                    }
                    else
                    {
                        result.IsError = true;
                        result.Message = "Location with the same cordinates exists.";
                    }
                }
                else
                {
                    result.IsError = true;
                    result.Message = "Invalid parameter";
                }
            }
            catch (Exception ex)
            {
                result.IsError = true;
                result.Message = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 30
0
        public async void DeleteAsync_GivenCategoryExistsAndInProjects_ReturnsSuccess()
        {
            var locationToDelete = new Location
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };;

            var creatorUser = new User()
            {
                Id = 1, Firstname = "First", Surname = "Surname", AzureUId = "Azure", Mail = "*****@*****.**"
            };

            var projects = new Project[]
            {
                new Project {
                    Title = "Project1", Location = locationToDelete, LocationId = locationToDelete.Id, CreatedDate = DateTime.Now, Description = "abcd", CreatorId = creatorUser.Id
                },
                new Project {
                    Title = "Project2", Location = locationToDelete, LocationId = locationToDelete.Id, CreatedDate = DateTime.Now, Description = "abcd", CreatorId = creatorUser.Id
                }
            };

            locationRepository = new LocationRepository(setupContextForIntegrationTests());

            context.Locations.Add(locationToDelete);
            context.Users.Add(creatorUser);
            context.Projects.AddRange(projects);
            context.SaveChanges();

            //Sanity Check
            Assert.NotNull(context.Locations.Find(locationToDelete.Id));
            Assert.Equal(2, (await context.Projects.ToArrayAsync()).Length);

            using (var logic = new LocationLogic(locationRepository, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.DeleteAsync(locationToDelete.Id);

                Assert.Equal(ResponseLogic.SUCCESS, response);
                foreach (var project in await context.Projects.ToArrayAsync())
                {
                    Assert.Null(project.Category);
                }
            }
        }