public async Task OffererDeleteComment()
        {
            // Arrange
            var user = UserRegisterModelFactory.getUserFactory("Offerer").getUser();

            var coupon = CouponModelFactory.Default();

            user.AddCoupon(coupon);
            var comment = new Comment("content", AuthenticatedUserId);

            coupon.AddComment(comment);
            await ExecuteDatabaseAction(async couponelContext =>
            {
                await couponelContext.Users.AddAsync(user);
                await couponelContext.SaveChangesAsync();
            });

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

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

            comments.Should().BeNull();
        }
Beispiel #2
0
        protected async Task <(Guid, string)> SetAuthenticationToken(string role)
        {
            var userFactory = UserRegisterModelFactory.getUserFactory(role);

            var userRegisterModel    = userFactory.getUserModel();
            var userRegisterResponse = await HttpClient.PostAsJsonAsync($"api/v1/auth/register", userRegisterModel);

            userRegisterResponse.IsSuccessStatusCode.Should().BeTrue();
            var user = userFactory.getUser();
            var authenticatedUserId = new Guid(userRegisterResponse.Headers.Location.OriginalString);
            var authenticateModel   = new AuthenticationRequest
            {
                Username = user.UserName,
                Password = userRegisterModel.Password
            };

            var userAuthenticateResponse = await HttpClient.PostAsJsonAsync($"api/v1/auth/login", authenticateModel);

            userAuthenticateResponse.IsSuccessStatusCode.Should().BeTrue();
            var authenticationResponseContent = await userAuthenticateResponse.Content.ReadAsAsync <AuthenticationResponse>();

            var userAuthenticationToken = authenticationResponseContent.Token;

            return(authenticatedUserId, userAuthenticationToken);
        }
Beispiel #3
0
        public async Task GetStudentUser()
        {
            // Arrange
            var admin      = UserRegisterModelFactory.getUserFactory("admin").getUser();
            var user       = UserRegisterModelFactory.getUserFactory("Student").getUser();
            var student    = new Student(user.Id);
            var university = InstitutionsModelFactory.University();
            var faculty    = InstitutionsModelFactory.Faculty();

            university.AddFaculty(faculty);
            faculty.AddStudent(student);
            await ExecuteDatabaseAction(async couponelContext =>
            {
                await couponelContext.Users.AddAsync(admin);
                await couponelContext.Users.AddAsync(user);
                await couponelContext.Universities.AddAsync(university);
                await couponelContext.SaveChangesAsync();
            });

            //Act
            var response = await HttpClient.GetAsync($"api/users/{user.Id}");

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

            users.Should().NotBeNull();
        }
Beispiel #4
0
        public async Task GetRedeemedCoupon()
        {
            // Arrange
            var offerer = UserRegisterModelFactory.getUserFactory("Offerer").getUser();
            var coupon  = CouponModelFactory.Default();

            offerer.AddCoupon(coupon);
            var student    = new Student(this.AuthenticatedUserId);
            var admin      = UserRegisterModelFactory.getUserFactory("Admin").getUser();
            var university = InstitutionsModelFactory.University();
            var faculty    = InstitutionsModelFactory.Faculty();

            university.AddFaculty(faculty);
            faculty.AddStudent(student);

            var redeemedcoupon = new RedeemedCoupon("Used", coupon.Id);

            student.AddRedeemedCoupon(redeemedcoupon);
            await ExecuteDatabaseAction(async couponelContext =>
            {
                await couponelContext.Users.AddAsync(admin);
                await couponelContext.Users.AddAsync(offerer);
                await couponelContext.Universities.AddAsync(university);
                await couponelContext.SaveChangesAsync();
            });

            //Act
            var response = await HttpClient.GetAsync($"/api/redeemedCoupons/{redeemedcoupon.Id}");

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

            redeemedcoupons.Should().NotBeNull();
        }
Beispiel #5
0
        public async Task DeleteFaculty()
        {
            // Arrange
            var user       = UserRegisterModelFactory.getUserFactory("Admin").getUser();
            var university = InstitutionsModelFactory.University();
            var faculty    = InstitutionsModelFactory.Faculty();

            university.AddFaculty(faculty);

            await ExecuteDatabaseAction(async couponelContext =>
            {
                await couponelContext.Users.AddAsync(user);
                await couponelContext.Universities.AddAsync(university);
                await couponelContext.SaveChangesAsync();
            });

            //Act
            var response = await HttpClient.DeleteAsync($"api/universities/{university.Id}/faculties/{faculty.Id}");

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

            faculties.Should().BeNull();
        }
        public async Task OffererDeletePhoto()
        {
            // Arrange
            var user   = UserRegisterModelFactory.getUserFactory("Offerer").getUser();
            var photo  = new Photo("Photo", await File.ReadAllBytesAsync("..\\..\\..\\Photo\\image.jpeg"), user.Id);
            var coupon = CouponModelFactory.Default();

            user.AddCoupon(coupon);
            coupon.AddPhoto(photo);
            coupon.RemovePhoto(photo.Id);
            await ExecuteDatabaseAction(async couponelContext =>
            {
                await couponelContext.Users.AddAsync(user);
                await couponelContext.SaveChangesAsync();
            });

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

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

            photos.Should().BeNull();
        }
Beispiel #7
0
        public async Task UpdateFaculty()
        {
            // Arrange
            var user       = UserRegisterModelFactory.getUserFactory("Admin").getUser();
            var university = InstitutionsModelFactory.University();
            var faculty    = InstitutionsModelFactory.Faculty();

            faculty.Update("faculty", "*****@*****.**", "0745624578", InstitutionsModelFactory.Address());
            university.AddFaculty(faculty);
            await ExecuteDatabaseAction(async couponelContext =>
            {
                await couponelContext.Users.AddAsync(user);
                await couponelContext.Universities.AddAsync(university);
                await couponelContext.SaveChangesAsync();
            });

            //Act
            var response = await HttpClient.GetAsync($"api/universities/{university.Id}/faculties/{faculty.Id}");

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

            faculties.Should().NotBeNull();
            faculties.Name.Should().BeEquivalentTo("faculty");
        }
Beispiel #8
0
        public void GivenValidate_WhenHavingAnPasswordLenghtLessThan8_ThenResultShouldBeInvalid()
        {
            var model          = UserRegisterModelFactory.Default().WithPassword(string.Create(2, '1', (a, b) => a.Fill(b)));
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #9
0
        public void GivenValidate_WhenHavingAnEmailLenghtEqualWith200_ThenResultShouldBeValid()
        {
            var model          = UserRegisterModelFactory.Default().WithEmail(string.Create(190, '1', (a, b) => a.Fill(b)) + "@gmail.com");
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeTrue();
        }
Beispiel #10
0
        public void GivenValidate_WhenHavingBucketListNameLenghEqual6_ThenResultShouldBeValid()
        {
            var model          = UserRegisterModelFactory.Default().WithBucketListName("123456");
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeTrue();
        }
Beispiel #11
0
        public void GivenValidate_WhenHavingAInValidEmail_ThenResultShouldBeInvalid()
        {
            var model          = UserRegisterModelFactory.Default().WithEmail("florin");
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
        public void GivenUserRegisterModel_WhenHavingAnInvalidEmailExtension_ThenResultShouldBeInvalid()
        {
            var model     = UserRegisterModelFactory.WithInvalidEmailExtension();
            var validator = new UserRegisterModelValidator();

            var result = validator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #13
0
        public void GivenValidate_WhenHavingYearMoreThan6_ThenResultShouldBeInvalid()
        {
            var model          = UserRegisterModelFactory.Default().WithYear(7);
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #14
0
        public void GivenValidate_WhenHavingAgeEqualWith99_ThenResultShouldBeValid()
        {
            var model          = UserRegisterModelFactory.Default().WithAge(99);
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #15
0
        public void GivenValidate_WhenHavingUsernameLenghtMoreThan50_ThenResultShouldBeInvalid()
        {
            var model          = UserRegisterModelFactory.Default().WithUsername(string.Create(51, '1', (a, b) => a.Fill(b)));
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #16
0
        public void GivenValidate_WhenHavingANullUsername_ThenResultShouldBeInvalid()
        {
            var model          = UserRegisterModelFactory.WithUsernameNull();
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #17
0
        public void GivenValidate_WhenHavingANullPassword_ThenResultShouldBeInvalid()
        {
            var model          = UserRegisterModelFactory.Default().WithPassword(null);
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
        public void GivenUserRegisterModel_WhenHavingEmailWithMoreThan50Characters_ThenResultShouldBeInvalid()
        {
            var model     = UserRegisterModelFactory.WithEmailHavingMoreThan50Characters();
            var validator = new UserRegisterModelValidator();

            var result = validator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #19
0
        public void GivenValidate_WhenHavingYearEqualWith6_ThenResultShouldBeValid()
        {
            var model          = UserRegisterModelFactory.Default().WithYear(6);
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeTrue();
        }
        public void GivenNoPassword_WhenHavingInvalidInput_ThenResultShouldBeInvalid()
        {
            var model     = UserRegisterModelFactory.WithPasswordNull();
            var validator = new UserRegisterModelValidator();

            var result = validator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #21
0
        public void GivenValidate_WhenHavingAnEmptyCity_ThenResultShouldBeInvalid()
        {
            var model          = UserRegisterModelFactory.Default().WithCity(Guid.Empty);
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #22
0
        public void GivenValidate_WhenHavingBucketListNameLenghtLessThan6_ThenResultShouldBeInvalid()
        {
            var model          = UserRegisterModelFactory.Default().WithBucketListName("1");
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #23
0
        public void GivenValidate_WhenHavingBucketListLengthEqualWith100_ThenResultShouldBeValid()
        {
            var model          = UserRegisterModelFactory.Default().WithBucketListName(string.Create(100, '1', (a, b) => a.Fill(b)));
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeTrue();
        }
        public void GivenUserRegisterModel_WhenHavingPasswordNotMatchingRegex_TheResultShouldBeInvalid()
        {
            var model = UserRegisterModelFactory.WithPasswordNotMatchingRegex();

            var validator = new UserRegisterModelValidator();

            var result = validator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #25
0
        public void GivenValidate_WhenHavingAValidInput_ThenResultShouldBeValid()
        {
            var model          = UserRegisterModelFactory.Default();
            var modelValidator = new UserRegisterModelValidator();

            var result = modelValidator.Validate(model);

            result.IsValid.Should().BeTrue();
            result.Errors.Count.Should().Be(0);
        }
        public void GivenUserRegisterModel_WhenHavingValidPassword_TheResultShouldBeValid()
        {
            var model = UserRegisterModelFactory.Default();

            var validator = new UserRegisterModelValidator();

            var result = validator.Validate(model);

            result.IsValid.Should().BeTrue();
        }
        public void GivenUserRegisterModel_WhenHavingUsernameEmpty_ThenResultShouldBeInvalid()
        {
            var model = UserRegisterModelFactory.WithUsernameEmpty();

            var validator = new UserRegisterModelValidator();

            var result = validator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
        public void GivenUserRegisterModel_WhenHavingInvalidAge_TheResultShouldBeInvalid()
        {
            var model = UserRegisterModelFactory.WithAgeBelow14();

            var validator = new UserRegisterModelValidator();

            var result = validator.Validate(model);

            result.IsValid.Should().BeFalse();
        }
Beispiel #29
0
        public async Task GetOffererUser()
        {
            // Arrange
            var user = UserRegisterModelFactory.getUserFactory("Offerer").getUser();

            await ExecuteDatabaseAction(async couponelContext =>
            {
                await couponelContext.Users.AddAsync(user);
                await couponelContext.SaveChangesAsync();
            });

            //Act
            var response = await HttpClient.GetAsync($"api/users/{user.Id}");

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

            users.Should().NotBeNull();
        }
Beispiel #30
0
        public async Task UpdateUniversity()
        {
            // Arrange
            var user       = UserRegisterModelFactory.getUserFactory("Admin").getUser();
            var university = InstitutionsModelFactory.University();

            university.Update("university", "*****@*****.**", "0456324862", InstitutionsModelFactory.Address());
            await ExecuteDatabaseAction(async couponelContext =>
            {
                await couponelContext.Users.AddAsync(user);
                await couponelContext.Universities.AddAsync(university);
                await couponelContext.SaveChangesAsync();
            });

            //Act
            var response = await HttpClient.GetAsync($"api/universities/{university.Id}");

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

            universities.Address.Street.Should().Be("Bucuriei");
        }