Esempio n. 1
0
        public async Task Update_NotFound()
        {
            // Setup
            var id    = "some_id";
            var input = new UpdatePublicationModel
            {
                Content = "some content"
            };

            var serviceMock = new Mock <IPublicationService>();

            serviceMock
            .Setup(s => s.GetByIdAsync(id))
            .ReturnsAsync(default(Publication));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(provider => serviceMock.Object);
            });

            // Act
            var response = await client.PutAsync($"/publications/{id}/", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 2
0
        public async Task Publication_NotFound()
        {
            // Setup
            var userId        = Guid.Parse("B4E69138-CE54-444A-8226-2CFABFD352C6");
            var publicationId = Guid.NewGuid().ToString();

            NewsFeedStorageMock
            .Setup(s => s.GetByIdAsync(publicationId))
            .ReturnsAsync(default(NewsFeedPublication));

            CurrentUserProviderMock
            .Setup(s => s.UserId)
            .Returns(userId.ToString());

            var client = TestServerHelper.New(collection =>
            {
                collection.AddAuthentication("Test")
                .AddScheme <AuthenticationSchemeOptions, TestAuthHandler>("Test", _ => { });
                collection.AddScoped(_ => NewsFeedStorageMock.Object);
                collection.AddScoped(_ => CurrentUserProviderMock.Object);
            });

            var input = new CreateNewsFeedPublication {
                Content = "123"
            };

            // Act
            var response = await client.PutAsync($"/newsfeed/{publicationId}", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 3
0
        public async Task Update_NotFound()
        {
            //Setup
            var id = Guid.NewGuid();

            var input = new ProfileUpdateViewModel()
            {
                FirstName   = "Upd",
                LastName    = "Upd",
                Gender      = "Upd",
                DateOfBirth = DateTimeOffset.Now.AddDays(1),
                City        = "Ct"
            };

            var serviceMock = new Mock <IProfileService>();

            serviceMock
            .Setup(x => x.UpdateAsync(id, input.FirstName, input.LastName, input.Gender, input.DateOfBirth, input.City, string.Empty))
            .ReturnsAsync(DomainResult.Error("NotFound"));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            //Act
            var response = await client.PutAsync($"profiles/{id}", input.AsJsonContent());

            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Esempio n. 4
0
        public async Task GetByAuthor_NotFound()
        {
            var authorKey   = "non_exist_author";
            var reactionKey = "non_exist_reaction";

            var storageMock = new Mock <IReactionStorage>();

            storageMock
            .Setup(s => s.GetReactionByAuthorAsync(reactionKey, authorKey))
            .ReturnsAsync(default(Reaction));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => storageMock.Object);
            });

            var request = new HttpRequestMessage(HttpMethod.Get, $"reactions/{reactionKey}/author");

            request.Headers.Add("author", authorKey);

            // Act
            var response = await client.SendAsync(request);

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 5
0
        public async Task Delete_NoContent()
        {
            //Setup
            var id = Guid.NewGuid();

            var serviceMock        = new Mock <IWorkExperienceService>();
            var profileServiceMock = new Mock <IProfileService>();

            serviceMock
            .Setup(x => x.GetByIdAsync(id))
            .ReturnsAsync(new Profiles.WorkExperiences.WorkExperience(id, It.IsAny <string>(), It.IsAny <string>(),
                                                                      DateTimeOffset.Now, DateTimeOffset.Now, Guid.NewGuid()));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
                collection.AddScoped(_ => profileServiceMock.Object);
            });

            //Act
            var response = await client.DeleteAsync($"/WorkExperiences/{id}");

            //Assert
            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
Esempio n. 6
0
        public async Task Create_Created()
        {
            //Setup
            var id = Guid.NewGuid();

            var model = new WorkExperienceCreateViewModel
            {
                CompanyName = "Some",
                Description = "Desc",
                StartWork   = DateTimeOffset.Now,
                FinishWork  = DateTimeOffset.Now.AddDays(1),
                ProfileId   = Guid.NewGuid()
            };

            var serviceMock        = new Mock <IWorkExperienceService>();
            var profileServiceMock = new Mock <IProfileService>();

            serviceMock
            .Setup(x => x.CreateAsync(model.CompanyName, model.Description, model.StartWork, model.FinishWork,
                                      model.ProfileId))
            .ReturnsAsync((DomainResult.Success(), id));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
                collection.AddScoped(_ => profileServiceMock.Object);
            });

            //Act
            var response = await client.PostAsync($"/WorkExperiences", model.AsJsonContent());

            //Assert
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
        }
        public async Task Comment_NotFound()
        {
            // Setup
            var userId    = Guid.Parse("B4E69138-CE54-444A-8226-2CFABFD352C6");
            var commentId = Guid.NewGuid().ToString();

            const string content = "New Content";

            NewsFeedCommentsStorageMock
            .Setup(s => s.GetByIdAsync(commentId))
            .ReturnsAsync(default(PublicationComment));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddAuthentication("Test")
                .AddScheme <AuthenticationSchemeOptions, TestAuthHandler>("Test", _ => { });
                collection.AddScoped(_ => NewsFeedStorageMock.Object);
            });

            var input = new UpdateNewsFeedComment {
                Content = content
            };

            // Act
            var response = await client.PutAsync($"/newsfeed/comments/{commentId}", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 8
0
        public async Task Update_NoContent()
        {
            // Setup
            var id    = "some_id";
            var input = new UpdatePublicationModel
            {
                Content = "some content"
            };

            var publication = new Publication(id, input.Content, Enumerable.Empty <string>(), null, DateTimeOffset.Now, DateTimeOffset.Now);

            var serviceMock = new Mock <IPublicationService>();

            serviceMock
            .Setup(s => s.UpdateAsync(id, input.Content))
            .ReturnsAsync(DomainResult.Success());

            serviceMock
            .Setup(s => s.GetByIdAsync(id))
            .ReturnsAsync(publication);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(provider => serviceMock.Object);
            });

            // Act
            var response = await client.PutAsync($"/publications/{id}/", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
Esempio n. 9
0
        public async Task Update_NotFound()
        {
            //Setup
            var id = Guid.NewGuid();

            var model = new WorkExperienceUpdateViewModel
            {
                CompanyName = "Company",
                Description = "Desc",
                StartWork   = DateTimeOffset.Now,
                FinishWork  = DateTimeOffset.Now.AddDays(1)
            };

            var profileServiceMock    = new Mock <IProfileService>();
            var experienceServiceMock = new Mock <IWorkExperienceService>();

            experienceServiceMock
            .Setup(x => x.UpdateAsync(id, model.CompanyName, model.Description, model.StartWork, model.FinishWork))
            .ReturnsAsync(DomainResult.Error("SomeError"));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => experienceServiceMock.Object);
                collection.AddScoped(_ => profileServiceMock.Object);
            });

            //Act
            var response = await client.PutAsync($"/WorkExperiences/{id}", model.AsJsonContent());

            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Esempio n. 10
0
        public async Task DeleteByKey_Ok()
        {
            // Setup
            var key = "key1";

            var stats = new Dictionary <string, int>
            {
                ["key2"] = 1
            };

            var storageMock = new Mock <IReactionStorage>();

            storageMock
            .Setup(s => s.GetStats(key))
            .ReturnsAsync(stats);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => storageMock.Object);
            });

            // Act
            var response = await client.DeleteAsync($"reactions/{key}");

            var result = await response.Content.DeserializeContent <Dictionary <string, int> >();

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(stats["key2"], result["key2"]);
        }
Esempio n. 11
0
        public async Task DeleteById_NoContent()
        {
            // Setup
            const string commentId     = "someId";
            const string publicationId = "somePublicationId";
            const string author        = "Some Author";

            var comment = new Comment(
                commentId,
                "content",
                DateTimeOffset.Now,
                publicationId,
                null,
                new UserInfo(Guid.Empty, author, null));

            var serviceMock = new Mock <ICommentsService>();

            serviceMock.Setup(s => s.GetByIdAsync(commentId)).ReturnsAsync(comment);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            // Act
            var response = await client.DeleteAsync($"/comments/{commentId}");

            // Assert
            Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent);
        }
Esempio n. 12
0
        public async Task Forbidden_Update_Other_Users()
        {
            // Setup
            var userId = Guid.Parse("B4E69138-CE54-444A-8226-2CFABFD352C6");
            var currentUserId = Guid.Parse("B4E69138-CE54-444A-8226-2CFABFD352C7");

            var usersStorageMock = new Mock<IUsersStorage>();
            var currentUserProviderMock = new Mock<ICurrentUserProvider>();
            currentUserProviderMock
                .Setup(s => s.UserId)
                .Returns(currentUserId.ToString());

            var client = TestServerHelper.New(collection =>
            {
                collection.AddAuthentication("Test")
                    .AddScheme<AuthenticationSchemeOptions, TestAuthHandler>("Test", _ => { });
                collection.AddScoped(_ => usersStorageMock.Object);
                collection.AddScoped(_ => currentUserProviderMock.Object);
            });

            // Act
            var response = await client.PutAsync($"/users/{userId}", new UpdateUserInput().AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode);
        }
Esempio n. 13
0
        public async Task DeleteByAuthor_NotFound()
        {
            // Setup
            var key    = "key1";
            var author = "some_author";

            var reactions = new Dictionary <string, int>();

            var storageMock = new Mock <IReactionStorage>();

            storageMock
            .Setup(s => s.GetStats(key))
            .ReturnsAsync(reactions);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => storageMock.Object);
            });

            var request = new HttpRequestMessage(HttpMethod.Delete, $"reactions/{key}/author");

            request.Headers.Add("author", author);

            // Act
            var response = await client.SendAsync(request);

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 14
0
        public async Task GetByAuthor_Ok()
        {
            // Setup
            var authorKey   = "some_author";
            var reactionKey = "some_reaction";
            var type        = "some_type";

            var reaction = new Reaction(reactionKey, type);

            var storageMock = new Mock <IReactionStorage>();

            storageMock
            .Setup(s => s.GetReactionByAuthorAsync(reactionKey, authorKey))
            .ReturnsAsync(reaction);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => storageMock.Object);
            });

            var request = new HttpRequestMessage(HttpMethod.Get, $"reactions/{reactionKey}/author");

            request.Headers.Add("author", authorKey);

            // Act
            var response = await client.SendAsync(request);

            var result = JsonConvert.DeserializeObject <Reaction>(await response.Content.ReadAsStringAsync());

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(reaction.Key, result.Key);
            Assert.AreEqual(reaction.Type, result.Type);
        }
Esempio n. 15
0
        public async Task SearchByIds_Ok()
        {
            //Setup
            var model = new ProfilesQueryModel()
            {
                Ids = new List <Guid>()
            };

            var serviceMock = new Mock <IProfileService>();

            serviceMock
            .Setup(x => x.SearchByIdsAsync(model.Ids))
            .ReturnsAsync(new List <Profiles.Profile>());

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            //Act
            var response = await client.PostAsync($"profiles/search", model.AsJsonContent());

            //Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Esempio n. 16
0
        public async Task User_Not_Found()
        {
            // Setup
            var userId = Guid.NewGuid();

            var usersStorageMock = new Mock<IUsersStorage>();
            usersStorageMock
                .Setup(s => s.GetByIdAsync(userId))
                .ReturnsAsync(default(User));

            var currentUserProviderMock = new Mock<ICurrentUserProvider>();
            currentUserProviderMock
                .Setup(s => s.UserId)
                .Returns(userId.ToString());

            var client = TestServerHelper.New(collection =>
            {
                collection.AddAuthentication("Test")
                    .AddScheme<AuthenticationSchemeOptions, TestAuthHandler>("Test", _ => { });
                collection.AddScoped(_ => usersStorageMock.Object);
                collection.AddScoped(_ => currentUserProviderMock.Object);
            });

            // Act
            var response = await client.PutAsync($"/users/{userId}", new UpdateUserInput().AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 17
0
        public async Task GetByUserId_Ok()
        {
            //Setup
            var userId = Guid.NewGuid();

            var securitySetting = new Profiles.SecuritySettings.SecuritySetting(
                userId,
                new SecuritySettingsSection(Access.Everyone, new List <Guid>()),
                new SecuritySettingsSection(Access.Everyone, new List <Guid>()));

            var serviceMock = new Mock <ISecuritySettingService>();

            serviceMock
            .Setup(x => x.GetByUserIdAsync(userId))
            .ReturnsAsync(securitySetting);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            //Act
            var response = await client.GetAsync($"/profiles/{userId}/security-settings");

            //Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Esempio n. 18
0
        public async Task Update_NotFound()
        {
            // Setup
            const string commentId = "someId";
            var          model     = new UpdateCommentModel
            {
                Content = "New Content"
            };

            DomainResult domainResult = DomainResult.Success();

            var serviceMock = new Mock <ICommentsService>();

            serviceMock.Setup(s => s.UpdateAsync(commentId, model.Content)).ReturnsAsync(domainResult);
            serviceMock.Setup(s => s.GetByIdAsync(commentId)).ReturnsAsync(default(Comment));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            // Act
            var response = await client.PutAsync($"comments/{commentId}", model.AsJsonContent());

            Assert.AreEqual(response.StatusCode, HttpStatusCode.NotFound);
        }
Esempio n. 19
0
        public async Task SearchFeatured_Ok()
        {
            // Setup
            const string firstPublicationId  = "firstId";
            const string secondPublicationId = "secondId";

            int commentId = 1;

            var author = new UserInfo(Guid.NewGuid(), "SomeName", null);

            var featuredComments = new Dictionary <string, FeaturedInfo>()
            {
                {
                    firstPublicationId, new FeaturedInfo(
                        new Comment[]
                    {
                        new Comment((commentId++).ToString(), "someContent1", DateTimeOffset.Now, firstPublicationId, null, author),
                        new Comment((commentId++).ToString(), "someContent2", DateTimeOffset.Now, firstPublicationId, null, author),
                    }, 2)
                },
                {
                    secondPublicationId, new FeaturedInfo(
                        new Comment[]
                    {
                        new Comment((commentId++).ToString(), "someContent1", DateTimeOffset.Now, secondPublicationId, null, author),
                        new Comment((commentId++).ToString(), "someContent2", DateTimeOffset.Now, secondPublicationId, null, author),
                    }, 2)
                }
            };

            var model = new FeaturedQuery()
            {
                Keys = new string[] { firstPublicationId, secondPublicationId }
            };

            var serviceMock = new Mock <ICommentsService>();

            serviceMock
            .Setup(s => s.SearchFeaturedAsync(new string[] { firstPublicationId, secondPublicationId }))
            .ReturnsAsync(featuredComments);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            // Act
            var response = await client.PostAsync("Comments/comments/featured", model.AsJsonContent());

            var result = await response.Content.DeserializeContent <Dictionary <string, FeaturedInfo> >();

            // Assert
            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);

            Assert.IsTrue(result.Count == 2);
            Assert.IsTrue(result[firstPublicationId].Comments.Count() == 2);
            Assert.IsTrue(result[secondPublicationId].Comments.Count() == 2);
        }
        public async Task Comment_BadRequest()
        {
            // Setup
            var userId        = Guid.Parse("B4E69138-CE54-444A-8226-2CFABFD352C6");
            var publicationId = Guid.NewGuid().ToString();
            var commentId     = Guid.NewGuid().ToString();

            const string oldContent = "Old Content";
            string       newContent = string.Empty;

            NewsFeedCommentsStorageMock
            .Setup(s => s.GetByIdAsync(commentId))
            .ReturnsAsync(
                new PublicationComment(
                    commentId,
                    oldContent,
                    publicationId,
                    new UserInfo(userId, string.Empty, null),
                    DateTimeOffset.Now));

            NewsFeedCommentsStorageMock
            .Setup(s => s.UpdateAsync(commentId, newContent))
            .ThrowsAsync(new ApiException {
                ErrorCode = (int)HttpStatusCode.BadRequest
            });

            CurrentUserProviderMock
            .Setup(s => s.UserId)
            .Returns(userId.ToString());

            var client = TestServerHelper.New(collection =>
            {
                collection.AddAuthentication("Test")
                .AddScheme <AuthenticationSchemeOptions, TestAuthHandler>("Test", _ => { });
                collection.AddScoped(_ => NewsFeedStorageMock.Object);
                collection.AddScoped(_ => CurrentUserProviderMock.Object);
            });

            var input = new UpdateNewsFeedComment {
                Content = newContent
            };

            // Act
            var response = await client.PutAsync($"/newsfeed/comments/{commentId}", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Esempio n. 21
0
        public async Task Create_Ok()
        {
            // Setup
            const string commentId     = "commentId";
            const string publicationId = "publicationId";
            const string content       = "asd";
            const string authorId      = "3fa85f64-5717-4562-b3fc-2c963f66afa7";

            var author = new UserInfo(new Guid(authorId), "FName LName", null);

            var model = new CreateCommentModel()
            {
                Key            = publicationId,
                Content        = content,
                ReplyCommentId = null,
                AuthorId       = authorId
            };

            var commentServiceMock = new Mock <ICommentsService>();

            commentServiceMock
            .Setup(s => s.CreateAsync(publicationId, content, null, author))
            .ReturnsAsync((DomainResult.Success(), "commentId"));

            commentServiceMock
            .Setup(s => s.GetByIdAsync(commentId))
            .ReturnsAsync(new Comment(commentId, content, DateTimeOffset.Now, publicationId, null, author));

            var userProvideMock = new Mock <IUserProvider>();

            userProvideMock
            .Setup(s => s.GetByIdAsync(model.AuthorId))
            .ReturnsAsync(author);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => commentServiceMock.Object);
                collection.AddScoped(_ => userProvideMock.Object);
            });

            // Act
            var response = await client.PostAsync("comments", model.AsJsonContent());

            // Asser
            Assert.AreEqual(response.StatusCode, HttpStatusCode.Created);
        }
Esempio n. 22
0
        public async Task GetById_NotFound()
        {
            // Setup
            const string commentId = "someId";

            var    serviceMock = new Mock <ICommentsService>();
            object p           = serviceMock.Setup(s => s.GetByIdAsync(commentId)).ReturnsAsync(default(Comment));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            // Act
            var response = await client.GetAsync($"/comments/{commentId}");

            // Assert
            Assert.AreEqual(response.StatusCode, HttpStatusCode.NotFound);
        }
Esempio n. 23
0
        public async Task Create_EmptyContent_BadRequest()
        {
            // Setup
            var input = new CreatePublicationModel
            {
                Content = null
            };

            var serviceMock = new Mock <IPublicationService>();

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(provider => serviceMock.Object);
            });

            // Act
            var response = await client.PostAsync("/publications/", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Esempio n. 24
0
        public async Task GetGroupedReactions_Ok()
        {
            // Setup
            var data = new Dictionary <string, Dictionary <string, int> >
            {
                { "Post_Test1", new Dictionary <string, int> {
                      ["like"] = 1, ["wow"] = 2
                  } },
                { "Post_Test2", new Dictionary <string, int> {
                      ["like"] = 1
                  } }
            };
            var keys = data.Select(d => d.Key);

            var storageMock = new Mock <IReactionStorage>();

            storageMock
            .Setup(s => s.GetGroupedReactionsAsync(keys))
            .ReturnsAsync(data);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => storageMock.Object);
            });

            var input = new ReactionsQuery {
                Keys = keys
            };

            // Act
            var response = await client.PostAsync("reactions/grouped", input.AsJsonContent());

            var result = await response.Content.DeserializeContent <Dictionary <string, Dictionary <string, int> > >();

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(2, result["Post_Test1"]["wow"]);
            Assert.AreEqual(1, result["Post_Test1"]["like"]);
            Assert.AreEqual(1, result["Post_Test2"]["like"]);
        }
Esempio n. 25
0
        public async Task GetById_NotFound()
        {
            //Setup
            var id = Guid.NewGuid();

            var serviceMock = new Mock <IProfileService>();

            serviceMock
            .Setup(x => x.GetByIdAsync(id))
            .ReturnsAsync(default(Profiles.Profile));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            //Act
            var response = await client.GetAsync($"profiles/{id}");

            //Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 26
0
        public async Task DeclineFriendRequest_NoContent()
        {
            //Setup
            var user      = Guid.NewGuid();
            var requester = Guid.NewGuid();

            var serviceMock = new Mock <IRelationsService>();

            serviceMock
            .Setup(x => x.DeclineRequestAsync(user, requester));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            //Act
            var response = await client.PutAsync($"/Relations/{user}/friends/{requester}/decline", null !);

            //Assert
            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
Esempio n. 27
0
        public async Task SendFriendRequest_BadRequest()
        {
            //Setup
            var fromUser = Guid.NewGuid();
            var toUser   = fromUser;

            var serviceMock = new Mock <IRelationsService>();

            serviceMock
            .Setup(x => x.SendRequestAsync(fromUser, toUser));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            //Act
            var response = await client.PostAsync($"/Relations/{fromUser}/friends/{toUser}", null !);

            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Esempio n. 28
0
        public async Task SearchOutgoingRequests_Ok()
        {
            //Setup
            var user = Guid.NewGuid();

            var serviceMock = new Mock <IRelationsService>();

            serviceMock
            .Setup(x => x.SearchIncomingRequestsAsync(0, 10, user))
            .ReturnsAsync((new List <Guid>(), 10));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            //Act
            var response = await client.GetAsync($"/Relations/{user}/friends/outgoing-requests");

            //Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Esempio n. 29
0
        public async Task GetByUserId_NotFound()
        {
            //Setup
            var userId = Guid.NewGuid();

            var serviceMock = new Mock <ISecuritySettingService>();

            serviceMock
            .Setup(x => x.GetByUserIdAsync(userId))
            .ReturnsAsync(default(Profiles.SecuritySettings.SecuritySetting));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            //Act
            var response = await client.GetAsync($"/profiles/{userId}/security-settings");

            //Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 30
0
        public async Task Delete_BadRequest()
        {
            //Setup
            var user   = Guid.NewGuid();
            var friend = user;

            var serviceMock = new Mock <IRelationsService>();

            serviceMock
            .Setup(x => x.DeleteFriendAsync(user, friend));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            //Act
            var response = await client.DeleteAsync($"/Relations/{user}/friends/{friend}");

            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }