Exemplo n.º 1
0
        public async virtual Task <IActionResult> GetMember(Guid teamId, Guid memberId)
        {
            var team = TeamRepository.Get(teamId);

            if (team == null)
            {
                return(this.NotFound());
            }
            else
            {
                var q = team.Members.Where(m => m.ID == memberId);
                if (q.Count() < 1)
                {
                    return(this.NotFound());
                }
                else
                {
                    Member member        = q.First();
                    var    locatedMember = new LocatedMember()
                    {
                        ID           = member.ID,
                        FirstName    = member.FirstName,
                        LastName     = member.LastName,
                        LastLocation = await this.LocationClient.GetLatestForMember(memberId)
                    };
                    return(this.Ok(locatedMember));
                }
            }
        }
Exemplo n.º 2
0
        public async virtual Task <IActionResult> GetMember(Guid teamID, Guid memberId)
        {
            Team team = _repository.Get(teamID);

            if (team == null)
            {
                return(NotFound());
            }
            else
            {
                var q = team.Members.Where(m => m.ID == memberId);

                if (q.Count() < 1)
                {
                    return(NotFound());
                }
                else
                {
                    //var member =_mapper.Map<LocatedMember>(q.First());
                    //locatedMember.LastLocation = await _locationClient.GetLatestForMember(locatedMember.ID);
                    var member        = q.First();
                    var locatedMember = new LocatedMember()
                    {
                        ID           = member.ID,
                        FirstName    = member.FirstName,
                        LastName     = member.LastName,
                        LastLocation = await _locationClient.GetLatestForMember(member.ID)
                    };
                    return(Ok(locatedMember));
                }
            }
        }
        public async Task <IActionResult> GetMember(Guid teamID, Guid memberId)
        {
            var team = await this.teamRepository.GetByIdAsync(teamID);

            if (team == null)
            {
                return(this.NotFound(teamID));
            }

            var teamMember = team.TeamMembers.FirstOrDefault(m => m.MemberId == memberId);

            if (teamMember == null)
            {
                return(this.NotFound(memberId));
            }

            var lastLocation = await this.locationClient.GetLatestForMemberAsync(teamMember.MemberId);

            var locatedMember = new LocatedMember
            {
                ID           = teamMember.MemberId,
                FirstName    = teamMember.Member.FirstName,
                LastName     = teamMember.Member.LastName,
                LastLocation = lastLocation
            };

            return(this.Ok(locatedMember));
        }
        public async void TestGetMemberReturnsLastLocation()
        {
            ITeamRepository   repository     = new TestMemoryTeamRepository();
            ILocationClient   locationClient = new MemoryLocationClient();
            MembersController controller     = new MembersController(repository, locationClient);

            Guid teamId    = Guid.NewGuid();
            Team team      = new Team("TestTeam", teamId);
            var  debugTeam = repository.Add(team);

            Guid   memberId  = Guid.NewGuid();
            Member newMember = new Member(memberId);

            newMember.FirstName = "Jim";
            newMember.LastName  = "Smith";
            controller.CreateMember(newMember, teamId);

            await locationClient.AddLocation(memberId, new LocationRecord()
            {
                Timestamp = 1,
                Altitude  = 123.45f
            });

            await locationClient.AddLocation(memberId, new LocationRecord()
            {
                Timestamp = 3,
                Altitude  = 123.47f
            });

            await locationClient.AddLocation(memberId, new LocationRecord()
            {
                Timestamp = 2,
                Altitude  = 123.46f
            });

            LocatedMember member = (LocatedMember)(await controller.GetMember(teamId, memberId) as ObjectResult).Value;

            Assert.Equal(member.ID, newMember.ID);
            Assert.NotNull(member.LastLocation);
            Assert.Equal(123.47f, member.LastLocation.Altitude);
        }
        public async void TestGetNewMemberReturnsMemberWithEmtpyLastLocation()
        {
            ITeamRepository   repository = new TestMemoryTeamRepository();
            MembersController controller = new MembersController(repository, new MemoryLocationClient());

            Guid teamId    = Guid.NewGuid();
            Team team      = new Team("TestTeam", teamId);
            var  debugTeam = repository.Add(team);

            Guid   memberId  = Guid.NewGuid();
            Member newMember = new Member(memberId);

            newMember.FirstName = "Jim";
            newMember.LastName  = "Smith";
            controller.CreateMember(newMember, teamId);

            LocatedMember member = (LocatedMember)(await controller.GetMember(teamId, memberId) as ObjectResult).Value;

            Assert.Equal(member.ID, newMember.ID);
            Assert.Null(member.LastLocation);
        }
Exemplo n.º 6
0
        public async void TestMemberAndLocationPostAndGet()
        {
            Guid memberId = Guid.NewGuid();
            Guid teamId   = Guid.NewGuid();

            //location
            LocationService.Models.LocationRecord locationRecord = new LocationService.Models.LocationRecord
            {
                ID        = Guid.NewGuid(),
                Latitude  = 1.3f,
                Altitude  = 22f,
                Longitude = 4.4f,
                Timestamp = 11,
                MemberID  = memberId
            };
            StringContent stringContent = new StringContent(
                System.Text.Json.JsonSerializer.Serialize(locationRecord),
                UnicodeEncoding.UTF8,
                "application/json");
            HttpResponseMessage postResponse = await locationClient.PostAsync(
                $"/locations/{memberId}",
                stringContent);

            postResponse.EnsureSuccessStatusCode();

            locationRecord.Timestamp = 12;
            stringContent            = new StringContent(
                System.Text.Json.JsonSerializer.Serialize(locationRecord),
                UnicodeEncoding.UTF8,
                "application/json");
            await locationClient.PostAsync($"/locations/{memberId}", stringContent);

            var getResponse = await locationClient.GetAsync($"/locations/{memberId}");

            getResponse.EnsureSuccessStatusCode();
            string raw = await getResponse.Content.ReadAsStringAsync();

            List <LocationService.Models.LocationRecord> locations = JsonConvert.DeserializeObject <List <LocationService.Models.LocationRecord> >(raw);

            Assert.Equal(2, locations.Count);

            //team
            var teamZombie = new Team()
            {
                ID   = teamId,
                Name = "Zombie"
            };

            StringContent teamStringContent = new StringContent(
                System.Text.Json.JsonSerializer.Serialize(teamZombie),
                UnicodeEncoding.UTF8,
                "application/json");
            HttpResponseMessage teamPostResponse = await teamClient.PostAsync(
                "/teams",
                teamStringContent);

            teamPostResponse.EnsureSuccessStatusCode();

            //member
            var member = new Member
            {
                ID        = memberId,
                FirstName = "zhi",
                LastName  = "xin"
            };
            StringContent memberStringContent = new StringContent(
                System.Text.Json.JsonSerializer.Serialize(member),
                UnicodeEncoding.UTF8,
                "application/json");
            HttpResponseMessage memeberPostResponse = await teamClient.PostAsync(
                $"/teams/{teamId}/members",
                memberStringContent);

            memeberPostResponse.EnsureSuccessStatusCode();

            //assert
            HttpResponseMessage memeberGetResponse = await teamClient.GetAsync(
                $"/teams/{teamId}/members/{memberId}");

            string rawMemner = await memeberGetResponse.Content.ReadAsStringAsync();

            LocatedMember located = JsonConvert.DeserializeObject <LocatedMember>(rawMemner);

            Assert.Equal(memberId, located.ID);
            Assert.Equal(12, located.LastLocation.Timestamp);
        }