public async Task AddActivityInBucketList()
        {
            //Arrange
            var        activityType = ActivityTypeFactory.Default();
            var        city         = CityFactory.Default();
            var        activity     = ActivityFactory.Default(city.Id, activityType.Id);
            BucketList bucket       = null;

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Cities.AddAsync(city);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();

                bucket = await doFestContext
                         .BucketLists
                         .FirstOrDefaultAsync(x => x.UserId == AuthenticatedUserId);
            });

            //Act
            var response = await HttpClient.PostAsync($"/api/v1/bucketlists/{bucket.Id}/activities/{activity.Id}", null);

            //Assert
            response.IsSuccessStatusCode.Should().BeTrue();
        }
        public async Task GetActivityPhotos()
        {
            //Arrange
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);

            var photo = new Photo(activity.Id, AuthenticatedUserId, new byte[1]);

            activity.AddPhoto(photo);

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            //Act
            var response = await HttpClient.GetAsync($"api/v1/activities/{activity.Id}/photos");

            // Assert
            response.IsSuccessStatusCode.Should().BeTrue();
            var photos = await response.Content.ReadAsAsync <IList <PhotoModel> >();

            photos.Should().HaveCount(1);
        }
Exemple #3
0
        public async Task FindAllNotificationsUserTest()
        {
            // Arrange
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);
            var notification = NotificationFactory.Default(activity.Id);

            activity.AddNotification(notification);

            BucketList         bucketList         = null;
            BucketListActivity bucketListActivity = null;

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.SaveChangesAsync();
                bucketList = await doFestContext.BucketLists.FirstOrDefaultAsync(entity => entity.UserId == AuthenticatedUserId);
                if (bucketList != null)
                {
                    bucketListActivity = new BucketListActivity(bucketList.Id, activity.Id);
                    await doFestContext.BucketListActivities.AddAsync(bucketListActivity);
                    await doFestContext.Activities.AddAsync(activity);
                    await doFestContext.SaveChangesAsync();
                }
            });

            // Act
            var response = await HttpClient.GetAsync("api/v1/notifications");

            // Assert
            response.IsSuccessStatusCode.Should().BeTrue();
            var notifications = await response.Content.ReadAsAsync <IList <Notification> >();

            notifications.Should().HaveCount(1);
        }
        public async Task GetActivityRatings()
        {
            //Arrange
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);

            var rating = new Rating(activityType.Id, this.AuthenticatedUserId, 5);

            activity.AddRating(rating);

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            //Act
            var response = await HttpClient.GetAsync($"api/v1/activities/{activity.Id}/ratings");

            // Assert
            response.IsSuccessStatusCode.Should().BeTrue();
            var ratings = await response.Content.ReadAsAsync <IList <RatingModel> >();

            ratings.Should().HaveCount(1);
        }
        public async Task AddNewActivity()
        {
            //Arrange
            var activityType = ActivityTypeFactory.Default();
            var city         = CityFactory.Default();

            var activity = new CreateActivityModel()
            {
                ActivityTypeId = activityType.Id,
                Address        = "test address",
                CityId         = city.Id,
                Description    = "test description",
                Name           = "test name"
            };

            //Act
            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Cities.AddAsync(city);
                await doFestContext.SaveChangesAsync();
            });

            //Assert
            var response = await HttpClient.PostAsJsonAsync($"/api/v1/activities", activity);

            response.IsSuccessStatusCode.Should().BeTrue();
        }
Exemple #6
0
        public async Task GetActivityComments()
        {
            // Arrange
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);
            var comment      = CommentFactory.Default(activity.Id, AuthenticatedUserId);

            activity.AddComment(comment);

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            // Act
            var response = await HttpClient.GetAsync($"/api/v1/activities/{activity.Id}/comments");

            // Assert
            response.IsSuccessStatusCode.Should().BeTrue();
            var comments = await response.Content.ReadAsAsync <IList <Comment> >();

            comments.Should().HaveCount(1);
        }
        public async Task DeleteActivity()
        {
            //Arrange
            var activityType = ActivityTypeFactory.Default();
            var city         = CityFactory.Default();
            var activity     = new Activity(activityType.Id, city.Id, "test name", "test description", "test address");

            //Act
            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Cities.AddAsync(city);
                await doFestContext.SaveChangesAsync();
            });

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            var response = await HttpClient.DeleteAsync($"/api/v1/activities/{activity.Id}");

            //Assert
            response.IsSuccessStatusCode.Should().BeTrue();
        }
Exemple #8
0
        public async Task AddCommentsToInvalidActivityId()
        {
            // Arrange
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            var newCommentModel = new NewCommentModel()
            {
                Content = "commentariu",
                UserId  = AuthenticatedUserId
            };

            // Act
            var response = await HttpClient.PostAsJsonAsync($"api/v1/activities/{Guid.NewGuid()}/comments", newCommentModel);

            // Assert
            response.IsSuccessStatusCode.Should().BeFalse();
        }
Exemple #9
0
        public async Task DeleteCommentFromActivity()
        {
            // Arrange
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);
            var comment      = CommentFactory.Default(activity.Id, AuthenticatedUserId);

            activity.AddComment(comment);
            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            // Act
            var response = await HttpClient.DeleteAsync($"api/v1/activities/{activity.Id}/comments/{comment.Id}");

            // Assert
            response.IsSuccessStatusCode.Should().BeTrue();
            Activity existingActvity = null;
            Comment  existingComment = null;

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                existingActvity = await doFestContext
                                  .Activities
                                  .Include(entity => entity.Comments)
                                  .FirstAsync(entity => entity.Id == activity.Id);
                existingComment = existingActvity.Comments.FirstOrDefault();
            });

            existingActvity.Comments.Should().HaveCount(0);
            existingComment.Should().BeNull();
        }
        public async Task DeleteActivityTypeTest()
        {
            var activityType = ActivityTypeFactory.Default();

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.SaveChangesAsync();
            });

            var response = await HttpClient.DeleteAsync($"api/v1/activities/types/{activityType.Id}");

            response.IsSuccessStatusCode.Should().BeTrue();
        }
        public async Task GetActivityTypesTest()
        {
            var activityType = ActivityTypeFactory.Default();

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.SaveChangesAsync();
            });

            var response = await HttpClient.GetAsync($"api/v1/activities/types");

            response.IsSuccessStatusCode.Should().BeTrue();
            var activityTypes = await response.Content.ReadAsAsync <IEnumerable <ActivityType> >();

            activityTypes.Should().HaveCount(1);
        }
        public async Task UpdateBucketList()
        {
            //Arrange
            var        activityType = ActivityTypeFactory.Default();
            var        city         = CityFactory.Default();
            var        activity     = ActivityFactory.Default(city.Id, activityType.Id);
            BucketList bucket       = null;
            var        updateModel  = new BucketListUpdateModel()
            {
                Name = "bucketlist test",
                ActivitiesForDelete = new List <Guid>(),
                ActivitiesForToggle = new List <Guid>()
            };

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                bucket = await doFestContext
                         .BucketLists
                         .FirstOrDefaultAsync(x => x.UserId == AuthenticatedUserId);
                await doFestContext.Cities.AddAsync(city);
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
                await doFestContext.BucketListActivities.AddAsync(new BucketListActivity(bucket.Id, activity.Id));
                await doFestContext.SaveChangesAsync();
            });

            //Act
            var response = await HttpClient.PutAsJsonAsync($"/api/v1/bucketlists/{bucket.Id}/activities", updateModel);

            //Assert
            response.IsSuccessStatusCode.Should().BeTrue();
            BucketList existingBucketList = null;

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                existingBucketList = await doFestContext
                                     .BucketLists
                                     .FirstOrDefaultAsync(x => x.UserId == AuthenticatedUserId);
            });

            existingBucketList.Should().NotBeNull();
            existingBucketList.Name.Should().Be(updateModel.Name);
        }
Exemple #13
0
        public async Task DeleteInvalidCommentFromAcvtivity()
        {
            // Arrange
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);
            var comment      = CommentFactory.Default(activity.Id, AuthenticatedUserId);

            activity.AddComment(comment);
            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            // Act
            var response = await HttpClient.DeleteAsync($"api/v1/activities/{activity.Id}/comments/{Guid.NewGuid()}");

            // Assert
            response.IsSuccessStatusCode.Should().BeFalse();
        }
        public async Task AddRatingToActivity()
        {
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            var createRatingModel = new CreateRatingModel
            {
                Stars = 5
            };

            //Act
            var response = await HttpClient.PostAsJsonAsync($"api/v1/activities/{activity.Id}/ratings",
                                                            createRatingModel);

            //Assert
            response.IsSuccessStatusCode.Should().BeTrue();

            var    createdRatingId = response.Headers.Location.OriginalString;
            Rating existingRating  = null;

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                var existingActivity = await doFestContext.Activities
                                       .Include(entity => entity.Ratings)
                                       .FirstAsync(entity => entity.Id == activity.Id);

                existingRating = existingActivity.Ratings.FirstOrDefault();
            });

            existingRating.Should().NotBeNull();
            existingRating.Id.Should().Be(createdRatingId);
        }
Exemple #15
0
        public async Task AddCommentsToActivity()
        {
            // Arrange
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            var newCommentModel = new NewCommentModel()
            {
                Content = "commentariu",
                UserId  = AuthenticatedUserId
            };

            // Act
            var response = await HttpClient.PostAsJsonAsync($"api/v1/activities/{activity.Id}/comments", newCommentModel);

            // Assert
            response.IsSuccessStatusCode.Should().BeTrue();
            var     createdCommentId = response.Headers.Location.OriginalString;
            Comment existingComment  = null;

            await ExecuteDatabaseAction(async (doFestContext) => {
                var existingActvity = await doFestContext
                                      .Activities
                                      .Include(entity => entity.Comments)
                                      .FirstAsync(entity => entity.Id == activity.Id);

                existingComment = existingActvity.Comments.FirstOrDefault();
            });

            existingComment.Should().NotBeNull();
            existingComment.Id.Should().Be(createdCommentId);
        }
        public async Task GetActivityById()
        {
            //Arrange
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);

            //Act
            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            var response = await HttpClient.GetAsync($"/api/v1/activities/{activity.Id}");

            //Assert
            response.IsSuccessStatusCode.Should().BeTrue();
            var activities = await response.Content.ReadAsAsync <Activity>();

            activities.Id.Should().Equals(activity.Id);
        }
        public async Task AddPhotoToActivity()
        {
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);


            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            var formData  = new MultipartFormDataContent();
            var imageFile = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")));

            formData.Add(imageFile, "image", "image.png");

            var response = await HttpClient.PostAsync($"api/v1/activities/{activity.Id}/photos",
                                                      formData);

            //Assert
            response.IsSuccessStatusCode.Should().BeTrue();

            var   createdPhotoId = response.Headers.Location.OriginalString;
            Photo existingPhoto  = null;

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                var existingActivity = await doFestContext.Activities
                                       .Include(entity => entity.Photos)
                                       .FirstAsync(entity => entity.Id == activity.Id);

                existingPhoto = existingActivity.Photos.FirstOrDefault();
            });

            existingPhoto.Should().NotBeNull();
            existingPhoto.Id.Should().Be(createdPhotoId);
        }
        public async Task DeletePhotoFromActivity()
        {
            //Arrange
            var activityType = ActivityTypeFactory.Default();
            var activity     = ActivityFactory.Default(CityId, activityType.Id);

            var photo = new Photo(activity.Id, AuthenticatedUserId, new byte[1]);

            activity.AddPhoto(photo);

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            //Act
            var response = await HttpClient.DeleteAsync($"api/v1/activities/{activity.Id}/photos/{photo.Id}");


            // Assert
            response.IsSuccessStatusCode.Should().BeTrue();
            Activity existingActvity = null;
            Photo    existingPhoto   = null;

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                existingActvity = await doFestContext
                                  .Activities
                                  .Include(entity => entity.Photos)
                                  .FirstAsync(entity => entity.Id == activity.Id);
                existingPhoto = existingActvity.Photos.FirstOrDefault();
            });

            existingActvity.Photos.Should().HaveCount(0);
            existingPhoto.Should().BeNull();
        }