Beispiel #1
0
        public void InsertNewsFeedTest()
        {
            string headline    = StringGenerator.RandomString(100);
            string subheadline = StringGenerator.RandomString(200);
            string author      = StringGenerator.RandomString(100);
            string story       = StringGenerator.RandomString(500);
            NewsFeedInsertRequest NewsFeedToInsert = new NewsFeedInsertRequest
            {
                Headline    = headline,
                SubHeadline = subheadline,
                Author      = author,
                Story       = story,
                EnteredBy   = firebaseFixture.H2UserId,
                OccupantId  = firebaseFixture.H2OccupantId,
                Recipient   = firebaseFixture.H1UserId,
            };

            RestClient  client  = GetClient();
            RestRequest request = apiCall <NewsFeedInsertRequest>(firebaseFixture.H2Token, sutEndpoint, sutHttpMethod, NewsFeedToInsert);
            IRestResponse <NewsFeedResponse> response = client.Execute <NewsFeedResponse>(request);

            string expectedContent = serialize(new NewsFeedResponse
            {
                NewsFeedId  = response.Data != null ? response.Data.NewsFeedId : 0,
                Headline    = headline,
                SubHeadline = subheadline,
                Author      = author,
                Story       = story,
                Recipient   = firebaseFixture.H1UserId,
            });

            response.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.OK);
            response.Data.NewsFeedId.Should().BePositive();
            response.Content.ShouldBeEquivalentTo(expectedContent);
        }
 public async Task <NewsFeedResponse> InsertNewsFeed(NewsFeedInsertRequest newsFeed)
 {
     return(await asyncConnection(newsFeed.EnteredBy, newsFeed.OccupantId, async db =>
     {
         return await InsertNewsFeedQuery(db, newsFeed);
     }));
 }
        public async Task <NewsFeedResponse> InsertNewsFeedQuery(IDbConnection db, NewsFeedInsertRequest newsFeed)
        {
            NewsFeedResponse newsFeedItem = await db.QueryFirstOrDefaultAsync <NewsFeedResponse>(
                sql : "[Houses].[NewsFeeds_Insert]",
                commandType : CommandType.StoredProcedure,
                param : newsFeed
                );

            return(newsFeedItem);
        }
        public async Task <bool> InviteOccupant(OccupantInviteRequest invite)
        {
            // TODO: Send invite email!
            return(await asyncConnection(invite.InvitedByUserId, invite.InvitedByOccupantId, async db =>
            {
                bool occupantInvited = false;
                OccupantInviteResponse existingOccupant = GetFirebaseUserByEmail(invite.Email);
                if (existingOccupant != null)
                {
                    this.logger.Information($"Creating Occupant from invite: {invite.ToString()}");
                    OccupantInsertRequest createOccupant = new OccupantInsertRequest
                    {
                        InviteAccepted = false,
                        UserId = existingOccupant.Uid,
                        DisplayName = existingOccupant.DisplayName,
                        EnteredBy = invite.InvitedByUserId,
                        InvitedByOccupantId = invite.InvitedByOccupantId
                    };
                    this.logger.Information($"Creating Occupant: {createOccupant.ToString()}");
                    OccupantResponse newOccupant = await this.InsertOccupantQuery(db, createOccupant);

                    this.logger.Information($"Created Occupant: {newOccupant.ToString()}");

                    NewsFeedInsertRequest householdInviteNewsItem = new NewsFeedInsertRequest
                    {
                        EnteredBy = invite.InvitedByUserId,
                        OccupantId = invite.InvitedByOccupantId,
                        Headline = "Invited to a new household",
                        SubHeadline = "Congrats",
                        Story = "You have been invited to a new household! Go to households to accept the invite.",
                        Author = invite.InvitedByUserId,
                        Recipient = newOccupant.UserId,
                    };
                    this.logger.Information($"Creating News Feed Invite: {invite.ToString()}");
                    await newsFeedsRepository.InsertNewsFeedQuery(db, householdInviteNewsItem);
                    occupantInvited = true;
                }
                else
                {
                    // TODO: Improve functionality here!
                    this.logger.Error("Existing occupant: {existingOccupant}, not found for email {invite}", existingOccupant, invite.Email);
                    throw new Exception($"The email address {invite.Email} must sign up to myHouse first");
                }

                return occupantInvited;
            }));
        }
Beispiel #5
0
        public void InvalidUserIdTest()
        {
            NewsFeedInsertRequest NewsFeedToInsert = new NewsFeedInsertRequest
            {
                Headline    = StringGenerator.RandomString(100),
                SubHeadline = StringGenerator.RandomString(200),
                Author      = StringGenerator.RandomString(100),
                Story       = StringGenerator.RandomString(500),
                EnteredBy   = firebaseFixture.H1UserId,
                OccupantId  = firebaseFixture.H2OccupantId,
                Recipient   = firebaseFixture.H2UserId,
            };

            RestClient    client   = GetClient();
            RestRequest   request  = apiCall(firebaseFixture.H2Token, sutEndpoint, sutHttpMethod, NewsFeedToInsert);
            IRestResponse response = client.Execute <NewsFeedResponse>(request);

            forbiddenExpectations(response);
        }
Beispiel #6
0
 public async Task <IActionResult> RequestNewsFeedInsert([FromBody] NewsFeedInsertRequest newsFeed)
 {
     return(await RequestHandler <NewsFeedResponse>(HttpVerbs.Get, newsFeed.EnteredBy, async() =>
                                                    await newsFeedsRepository.InsertNewsFeed(newsFeed)));
 }