Esempio n. 1
0
        public async Task Put_NewMetadataTypeAndTag_GetByName_EndpointsReturnSuccess_CorrectContentType(string url)
        {
            // Arrange

            var             client          = _factory.CreateDefaultClient();
            NewUserResource newUserResource = new NewUserResource();

            newUserResource.Mail     = "*****@*****.**";
            newUserResource.Password = "******";
            newUserResource.UserType = UserType.Municipality;
            await client.PutAsync("api/user", ResponseSerializer.Serialize(newUserResource));

            AuthUserResource loginResource = new AuthUserResource();

            loginResource.Mail     = newUserResource.Mail;
            loginResource.Password = newUserResource.Password;
            var loginResponse = await client.PostAsync("/api/user/auth", ResponseSerializer.Serialize(loginResource));

            Assert.NotNull(loginResponse.Content);
            var user = ResponseSerializer.Extract <PrivateSafeUserResource>(loginResponse);

            Assert.Equal(loginResource.Mail, user.Mail);
            string token = user.Token;

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);


            var newCategory = new SaveMetadataCategoryResource {
                ParentUuid = null, Name = "Test Category"
            };
            var newCategoryResponse = await client.PutAsync("api/metadatacategory", ResponseSerializer.Serialize(newCategory));

            newCategoryResponse.EnsureSuccessStatusCode();

            var category = ResponseSerializer.Extract <MetadataCategory>(newCategoryResponse);

            SaveMetadataTypeResource newMetadataTypeResource = new SaveMetadataTypeResource
            {
                CategoryUuid = category.Uuid,
                Name         = "Test"
            };

            // Act

            var metadataTypeResponse = await client.PutAsync(url, ResponseSerializer.Serialize(newMetadataTypeResource));

            var metadataType = ResponseSerializer.Extract <MetadataTypeResource>(metadataTypeResponse);

            var responseForGetByName = await client.GetAsync(url + "/" + metadataType.Uuid);

            // Assert

            metadataTypeResponse.EnsureSuccessStatusCode(); // Status Code 200-299
            Assert.Equal("application/json; charset=utf-8",
                         metadataTypeResponse.Content.Headers.ContentType.ToString());

            responseForGetByName.EnsureSuccessStatusCode(); // Status Code 200-299
            Assert.Equal("application/json; charset=utf-8",
                         responseForGetByName.Content.Headers.ContentType.ToString());
        }
Esempio n. 2
0
        public async Task FetchDescriptionsTest()
        {
            var client = _factory.CreateDefaultClient();

            NewUserResource newUserResource = new NewUserResource();

            newUserResource.Mail     = "*****@*****.**";
            newUserResource.Password = "******";
            newUserResource.UserType = UserType.Municipality;
            await client.PutAsync("api/user", ResponseSerializer.Serialize(newUserResource));

            AuthUserResource loginResource = new AuthUserResource();

            loginResource.Mail     = newUserResource.Mail;
            loginResource.Password = newUserResource.Password;
            var loginResponse = client.PostAsync("/api/user/auth", ResponseSerializer.Serialize(loginResource)).Result;

            Assert.NotNull(loginResponse.Content);
            var user = ResponseSerializer.Extract <PrivateSafeUserResource>(loginResponse);

            Assert.Equal(loginResource.Mail, user.Mail);
            string token = user.Token;

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);


            var newCategory = new SaveMetadataCategoryResource {
                ParentUuid = null, Name = "Super Category"
            };
            var newCategoryResponse = await client.PutAsync("api/metadatacategory", ResponseSerializer.Serialize(newCategory));

            newCategoryResponse.EnsureSuccessStatusCode();

            var category = ResponseSerializer.Extract <MetadataCategory>(newCategoryResponse);

            SaveMetadataTypeResource newMetadataTypeResource = new SaveMetadataTypeResource {
                CategoryUuid = category.Uuid, Name = "Super MetadataType"
            };
            var newMetadataTypeResponse = await client.PutAsync("api/metadatatype", ResponseSerializer.Serialize(newMetadataTypeResource));

            newMetadataTypeResponse.EnsureSuccessStatusCode();
            var metadataType = ResponseSerializer.Extract <MetadataTypeResource>(newMetadataTypeResponse);

            var fetchDescriptionsResponse = await client.GetAsync("api/metadatatype/" + metadataType.Uuid + "/description");

            fetchDescriptionsResponse.EnsureSuccessStatusCode();
        }
Esempio n. 3
0
        public async Task PutCommentsAndReplyToCommentTest()
        {
            var client = _factory.CreateDefaultClient();

            NewUserResource newUserResource = new NewUserResource();

            newUserResource.Mail     = "*****@*****.**";
            newUserResource.Password = "******";
            newUserResource.UserType = UserType.Municipality;
            await client.PutAsync("api/user", ResponseSerializer.Serialize(newUserResource));

            AuthUserResource loginResource = new AuthUserResource();

            loginResource.Mail     = newUserResource.Mail;
            loginResource.Password = newUserResource.Password;
            var loginResponse = client.PostAsync("/api/user/auth", ResponseSerializer.Serialize(loginResource)).Result;

            Assert.NotNull(loginResponse.Content);
            var user = ResponseSerializer.Extract <PrivateSafeUserResource>(loginResponse);

            Assert.Equal(loginResource.Mail, user.Mail);
            string token = user.Token;

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);


            var newCategory = new SaveMetadataCategoryResource {
                ParentUuid = null, Name = "Super Category"
            };
            var newCategoryResponse = await client.PutAsync("api/metadatacategory", ResponseSerializer.Serialize(newCategory));

            newCategoryResponse.EnsureSuccessStatusCode();

            var category = ResponseSerializer.Extract <MetadataCategory>(newCategoryResponse);

            SaveMetadataTypeResource newMetadataTypeResource = new SaveMetadataTypeResource {
                CategoryUuid = category.Uuid, Name = "Super MetadataType"
            };
            var newMetadataTypeResponse = await client.PutAsync("api/metadatatype", ResponseSerializer.Serialize(newMetadataTypeResource));

            newMetadataTypeResponse.EnsureSuccessStatusCode();
            var metadataType = ResponseSerializer.Extract <MetadataTypeResource>(newMetadataTypeResponse);

            SaveMetadataResource saveMetadata = new SaveMetadataResource {
                Description      = "Test",
                MetadataTypeUuid = metadataType.Uuid,
                MunicipalityName = user.MunicipalityName,
                ReleaseState     = EReleaseState.Green
            };

            var newMetadataResponse = await client.PutAsync("api/metadata/", ResponseSerializer.Serialize(saveMetadata));

            newMetadataResponse.EnsureSuccessStatusCode();
            var metadata = ResponseSerializer.Extract <MetadataResource>(newMetadataResponse);

            var newComment = new NewCommentResource {
                Content = "Well hello there!"
            };
            var putCommentResponse = await client.PutAsync("api/comment/metadata/" + metadata.Uuid, ResponseSerializer.Serialize(newComment));

            putCommentResponse.EnsureSuccessStatusCode();
            var comment = ResponseSerializer.Extract <CommentResource>(putCommentResponse);

            Assert.Equal(newComment.Content, comment.Content);
            Assert.Equal(user.Mail, comment.UserMail);

            var newReplyComment = new NewCommentResource {
                Content = "Well, well, well hello there!"
            };

            var replyCommentResponse = await client.PutAsync("api/comment/reply/" + comment.Uuid, ResponseSerializer.Serialize(newReplyComment));

            replyCommentResponse.EnsureSuccessStatusCode();
            var replyComment = ResponseSerializer.Extract <CommentResource>(replyCommentResponse);

            Assert.Equal(comment.Uuid, replyComment.ParentCommentUuid);
            Assert.Equal(newReplyComment.Content, replyComment.Content);
            Assert.Equal(user.Mail, replyComment.UserMail);

            var newExperiencePost = new SaveExperiencePostResource {
                Title    = "Big Test",
                Contents = "Test"
            };
            var newExperiencePostResponse = await client.PutAsync("api/metadata/" + metadata.Uuid + "/experience", ResponseSerializer.Serialize(newExperiencePost));

            newExperiencePostResponse.EnsureSuccessStatusCode();
            var experiencePost = ResponseSerializer.Extract <ExperiencePostResource>(newExperiencePostResponse);

            var newCommentExperiencePost = new NewCommentResource {
                Content = "Well hello there experience!"
            };
            var putCommentExperiencePost = await client.PutAsync("api/comment/experiencepost/" + experiencePost.Uuid, ResponseSerializer.Serialize(newCommentExperiencePost));

            putCommentExperiencePost.EnsureSuccessStatusCode();
            var commentExperiencePost = ResponseSerializer.Extract <CommentResource>(putCommentExperiencePost);

            Assert.Equal(newCommentExperiencePost.Content, commentExperiencePost.Content);
            Assert.Equal(user.Mail, commentExperiencePost.UserMail);
        }