예제 #1
0
        public IHttpActionResult RequestToBeHost([FromBody] HostRequestDto hostRequest)
        {
            return(Authorized(token =>
            {
                try
                {
                    _finderService.RequestToBeHost(token, hostRequest);

                    // Call Analytics
                    var props = new EventProperties {
                        { "City", hostRequest.Address.City }, { "State", hostRequest.Address.State }, { "Zip", hostRequest.Address.PostalCode }
                    };
                    _analyticsService.Track(hostRequest.ContactId.ToString(), "RegisteredAsHost", props);

                    return Ok();
                }
                catch (GatheringException e)
                {
                    _logger.Error("Host already has a gathering at this location.", e);
                    throw new HttpResponseException(HttpStatusCode.NotAcceptable);
                }
                catch (Exception e)
                {
                    _logger.Error("Could not generate request", e);
                    throw new HttpResponseException(new ApiErrorDto("Gathering request failed", e).HttpResponseMessage);
                }
            }));
        }
예제 #2
0
        public void TestRequestToBeHost()
        {
            var token          = "faketoken";
            var hostRequestDto = new HostRequestDto
            {
                ContactId        = 123,
                GroupDescription = "fake group description",
                IsHomeAddress    = false,
                ContactNumber    = "555-123-4567",
                Address          = new AddressDTO
                {
                    AddressID    = 1,
                    AddressLine1 = "123 Main St",
                    City         = "Cincinnati",
                    State        = "OH",
                    PostalCode   = "45249"
                }
            };

            var contact = new MpMyContact
            {
                Contact_ID    = 123,
                Email_Address = "*****@*****.**",
                Nickname      = "Bob",
                Last_Name     = "Bobert"
            };
            var participant = new MpParticipant {
                ParticipantId = 999
            };

            var group = new GroupDTO();

            group.GroupId = 555;


            _mpContactRepository.Setup(m => m.GetContactById(It.IsAny <int>())).Returns(contact);
            _mpParticipantRepository.Setup(m => m.GetParticipant(It.IsAny <int>())).Returns(participant);
            _groupService.Setup(m => m.CreateGroup(It.IsAny <GroupDTO>())).Returns(group);
            _groupService.Setup(m => m.addParticipantToGroupNoEvents(It.IsAny <int>(), It.IsAny <ParticipantSignup>()));
            _addressService.Setup(m => m.CreateAddress(It.IsAny <AddressDTO>())).Returns(57);

            _mpGroupRepository.Setup(m => m.GetGroupsByGroupType(It.IsAny <int>())).Returns(new List <MpGroup>());

            _fixture.RequestToBeHost(token, hostRequestDto);

            _groupService.Verify(x => x.addParticipantToGroupNoEvents(It.IsAny <int>(), It.IsAny <ParticipantSignup>()), Times.Once);
            _mpContactRepository.Verify(x => x.SetHouseholdAddress(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()), Times.Never);
        }
예제 #3
0
        public void RequestToBeAHostShouldCallAnalytics()
        {
            var token = "good ABC";

            _fixture.SetupAuthorization("good", "ABC");
            var fakeRequest = new HostRequestDto()
            {
                Address = new AddressDTO()
                {
                    City       = "City!",
                    State      = "OH",
                    PostalCode = "12345"
                },
                ContactId = 42
            };

            _finderService.Setup(m => m.RequestToBeHost(
                                     It.Is <string>(toke => toke.Equals(token)),
                                     It.Is <HostRequestDto>(dto =>
                                                            dto.Address.City.Equals(fakeRequest.Address.City) &&
                                                            dto.Address.State.Equals(fakeRequest.Address.State) &&
                                                            dto.Address.PostalCode.Equals(fakeRequest.Address.PostalCode) &&
                                                            dto.ContactId.Equals(fakeRequest.ContactId))
                                     ));

            _analyticsService.Setup(m => m.Track(
                                        It.Is <string>(contactId => contactId.Equals(fakeRequest.ContactId.ToString())),
                                        It.Is <string>(eventName => eventName.Equals("RegisteredAsHost")),
                                        It.Is <EventProperties>(props =>
                                                                props["City"].Equals(fakeRequest.Address.City) &&
                                                                props["State"].Equals(fakeRequest.Address.State) &&
                                                                props["Zip"].Equals(fakeRequest.Address.PostalCode))
                                        ));
            _fixture.RequestToBeHost(fakeRequest);
            _finderService.VerifyAll();
            _analyticsService.VerifyAll();
        }
예제 #4
0
        public void RequestToBeHostShouldThrow()
        {
            var token          = "faketoken";
            var hostRequestDto = new HostRequestDto
            {
                ContactId        = 123,
                GroupDescription = "fake group description",
                IsHomeAddress    = false,
                ContactNumber    = "555-123-4567",
                Address          = new AddressDTO
                {
                    AddressLine1 = "123 Main St",
                    City         = "Cincinnati",
                    State        = "OH",
                    PostalCode   = "45249"
                }
            };

            var searchResult1 = new MpGroup
            {
                ContactId      = 456,
                PrimaryContact = "456",
                Address        = new MpAddress()
                {
                    Address_ID     = 1,
                    Address_Line_1 = "42 Elm St",
                    City           = "Florence",
                    State          = "KY",
                    Postal_Code    = "45202"
                }
            };
            var searchResult2 = new MpGroup
            {
                ContactId      = 123,
                PrimaryContact = "123",
                Address        = new MpAddress()
                {
                    Address_ID     = 2,
                    Address_Line_1 = "123 Main St",
                    City           = "Cincinnati",
                    State          = "OH",
                    Postal_Code    = "45249"
                }
            };

            var searchResult3 = new MpGroup
            {
                ContactId      = 123,
                PrimaryContact = "123",
                Address        = new MpAddress()
                {
                    Address_ID     = 2,
                    Address_Line_1 = "99 SomewhereElse Ave",
                    City           = "Cincinnati",
                    State          = "OH",
                    Postal_Code    = "45249"
                }
            };
            var searchResults = new List <MpGroup> {
                searchResult1, searchResult2, searchResult3
            };

            _mpGroupRepository.Setup(m => m.GetGroupsByGroupType(It.IsAny <int>())).Returns(searchResults);

            Assert.That(() => _fixture.RequestToBeHost(token, hostRequestDto),
                        Throws.Exception
                        .TypeOf <GatheringException>());
        }