Exemplo n.º 1
0
        public async void FindWildCardAsyncAsync_GivenStrings_ReturnsLocationsOrNull()
        {
            var cop = new LocationCreateDTO
            {
                City    = "Copenhagen",
                Country = "Denmark"
            };

            var ber = new LocationCreateDTO
            {
                City    = "Berlin",
                Country = "Germany"
            };

            var war = new LocationCreateDTO
            {
                City    = "Warszawa",
                Country = "Poland"
            };

            var krak = new LocationCreateDTO
            {
                City    = "Krakow",
                Country = "Poland"
            };

            using (var repository = new LocationRepository(context))
            {
                await repository.CreateAsync(cop);

                await repository.CreateAsync(ber);

                await repository.CreateAsync(war);

                await repository.CreateAsync(krak);

                var res = await repository.FindWildcardAsync("z");

                foreach (var item in res)
                {
                    Assert.Equal(war.City, item.City);
                }
                var rese = new List <LocationDTO>(await repository.FindWildcardAsync("e"));
                Assert.Equal(2, rese.Count);

                // We dont want to optimize for alphabet.
                Assert.Equal("Copenhagen", rese[0].City);
                Assert.Equal("Denmark", rese[0].Country);
                Assert.Equal("Berlin", rese[1].City);
                Assert.Equal("Germany", rese[1].Country);

                var expectedEmpty = new List <LocationDTO>(await repository.FindWildcardAsync("e", "Sweden"));
                Assert.Equal(0, expectedEmpty.Count);
            }
        }
        public async void CreateAsync_GivenValidInformation_CheckIfProjectWasCreatedThenDelete()
        {
            var loc = new LocationCreateDTO()
            {
                City    = "Copenhagen",
                Country = "Denmark"
            };

            using (var repo = new LocationRepository(context))
            {
                var id = await repo.CreateAsync(loc);

                var location = await repo.FindAsync(id);

                var project = new CreateProjectDTO
                {
                    Title       = "Super hot flaming bicycle",
                    Description = "This project is about creating the coolest bike ever.",
                    Location    = location
                };

                using (var repo1 = new ProjectRepository(context))
                {
                    var idproj = await repo1.CreateAsync(project, creator.Id);

                    Assert.NotNull(await context.Projects.FindAsync(idproj));
                    Assert.True(await repo1.DeleteAsync(idproj));
                }
            }
        }
Exemplo n.º 3
0
        public async void ReadOrderedAsync_GivenLocations_ReturnsOrderedArray()
        {
            var cop = new LocationCreateDTO
            {
                City    = "Copenhagen",
                Country = "Denmark"
            };

            var ber = new LocationCreateDTO
            {
                City    = "Berlin",
                Country = "Germany"
            };

            var war = new LocationCreateDTO
            {
                City    = "Warszawa",
                Country = "Poland"
            };

            var krak = new LocationCreateDTO
            {
                City    = "Krakow",
                Country = "Poland"
            };

            using (var repository = new LocationRepository(context))
            {
                await repository.CreateAsync(war);

                await repository.CreateAsync(krak);

                await repository.CreateAsync(cop);

                await repository.CreateAsync(ber);

                var rese = new List <LocationDTO>(await repository.ReadOrderedAsync());
                Assert.Equal(4, rese.Count);

                // We dont want to optimize for alphabet.
                Assert.Equal("Copenhagen", rese[0].City);
                Assert.Equal("Berlin", rese[1].City);
                Assert.Equal("Krakow", rese[2].City);
                Assert.Equal("Warszawa", rese[3].City);
            }
        }
Exemplo n.º 4
0
        public async void CreateAsync_GivenSaveThrowsException_ReturnsDbUpdateException()
        {
            var contextMock = new Mock <ICrowdSparkContext>();

            contextMock.Setup(c => c.Locations.Add(It.IsAny <Location>()));
            contextMock.Setup(c => c.SaveChangesAsync(default(CancellationToken))).ThrowsAsync(new System.Data.DataException("Error", default(Exception)));

            using (var repo = new LocationRepository(contextMock.Object))
            {
                await Assert.ThrowsAsync <DbUpdateException>(() => repo.CreateAsync(new LocationCreateDTO()
                {
                }));
            }
        }
Exemplo n.º 5
0
        public async void CreateAsync_GivenValidLocation_ReturnsNewLocationID()
        {
            var loc = new LocationCreateDTO
            {
                City    = "Copenhagen",
                Country = "Denmark"
            };

            using (var repository = new LocationRepository(context))
            {
                var id = await repository.CreateAsync(loc);

                Assert.Equal((await context.Locations.FirstAsync()).Id, id);
            }
        }
        public async Task <int> CreateLocation(LocationBody locationBody)
        {
            // save image to blob
            string imageName = await azureService.saveImageToBlobStorage(locationBody.Image);

            // create new location
            Location newLocation = new Location
            {
                Name  = locationBody.Name,
                City  = locationBody.City,
                Lat   = locationBody.Lat,
                Lng   = locationBody.Lng,
                Image = imageName
            };

            // save location to database
            await locationRepository.CreateAsync(newLocation);

            return(newLocation.Id);
        }
Exemplo n.º 7
0
        public async void UpdateAsync_GivenGoodIDReturnTrue()
        {
            var loc = new LocationCreateDTO
            {
                City    = "Copenhagen",
                Country = "Denmark"
            };

            var locupdate = new LocationDTO
            {
                Id      = 1,
                City    = "Copenhagen",
                Country = "Denmark"
            };

            using (var repository = new LocationRepository(context))
            {
                var id = await repository.CreateAsync(loc);

                Assert.True(await repository.UpdateAsync(locupdate));
            }
        }