Example #1
0
        public async void PostPlace_doesntaddPlaceAndReturnsNotFoundWhenUserDoesntExist()
        {
            var options = new DbContextOptionsBuilder <DatabaseContext>().UseInMemoryDatabase(databaseName: "PostPlaceTest2").Options;

            using (var context = new DatabaseContext(options))
            {
                // Arrange
                string ownerId    = "1";
                var    controller = new PlacesController(context);
                AddUserClaim(controller, ownerId);
                var place = new Place()
                {
                    Name          = "Place1",
                    City          = "Warsaw",
                    StreetAddress = "Słoneczna 1/5",
                    OwnerId       = ownerId,
                };
                var place2 = new Place()
                {
                    Name          = "Place2",
                    City          = "Warsaw",
                    StreetAddress = "Słoneczna 1/5",
                    OwnerId       = ownerId,
                };

                // Act
                var result = await controller.PostPlace(place);

                var result2 = await controller.PostPlace(place2);

                // Assert
                Assert.IsType <NotFoundResult>(result);
                Assert.IsType <NotFoundResult>(result2);
            }
        }
Example #2
0
        public async void PostPlace_addsPlaceAndReturnsOk()
        {
            var options = new DbContextOptionsBuilder <DatabaseContext>().UseInMemoryDatabase(databaseName: "PostPlaceTest").Options;

            using (var context = new DatabaseContext(options))
            {
                // Arrange
                string ownerId    = "1";
                var    controller = new PlacesController(context);
                AddUserClaim(controller, ownerId);
                var place = new Place()
                {
                    Name          = "Place1",
                    City          = "Warsaw",
                    StreetAddress = "Słoneczna 1/5",
                    OwnerId       = ownerId,
                };
                var place2 = new Place()
                {
                    Name          = "Place2",
                    City          = "Warsaw",
                    StreetAddress = "Słoneczna 1/5",
                    OwnerId       = ownerId,
                };

                // Act
                context.Users.Add(new User()
                {
                    FacebookId = ownerId
                });
                context.SaveChanges();

                var result = await controller.PostPlace(place);

                var result2 = await controller.PostPlace(place2);

                // Assert
                Assert.IsType <OkResult>(result);
                Assert.IsType <OkResult>(result2);

                var places = await controller.Get();

                var placesCount   = places.Value.Count();
                var expectedCount = 2;
                Assert.Equal(expectedCount, placesCount);
            }
        }