Esempio n. 1
0
        public async Task <GetPeopleResponse> GetPeople(GetPeopleRequest request)
        {
            const string userMessage = "Unable to get People";
            var          response    = new GetPeopleResponse();

            try
            {
                var people = await _dbContext.People.OrderBy(p => p.FirstName).ToListAsync();

                response.People = people.Select(p =>
                                                new PersonInformation
                {
                    Id        = p.Id,
                    FirstName = p.FirstName,
                    LastName  = p.LastName,
                    Email     = p.Email,
                    Photo     = p.Photo
                });

                response.Success = true;
                return(response);
            }
            catch (Exception ex)
            {
                //log the exception..
                //In production we wouldn't return the exception detail
                return(new GetPeopleResponse
                {
                    Success = false,
                    FailureInformation = userMessage + " | " + ex.Message
                });
            }
        }
Esempio n. 2
0
        public async Task <List <PersonDto> > Handle(GetPeopleRequest request, CancellationToken cancellationToken)
        {
            var people = await _context.Set <Person>()
                         .Select(person => _mapper.Map <PersonDto>(person))
                         .ToListAsync();

            return(people);
        }
Esempio n. 3
0
 public override Task <GetPeopleResponse> GetPeople(GetPeopleRequest request, ServerCallContext context)
 {
     return(Task.FromResult(new GetPeopleResponse
     {
         People =
         {
             new Person {
                 FirstName = "John",
                 LastName = "Elmer",
                 StartDate = Timestamp.FromDateTime(DateTime.ParseExact("1975-10-17T22:20:29.055Z", "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal)),
                 Rating = 6
             },
             new Person
             {
                 FirstName = "Francis",
                 LastName = "Hunt",
                 StartDate = Timestamp.FromDateTime(DateTime.ParseExact("2000-02-06T22:20:29.055Z", "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal)),
                 Rating = 7
             },
             new Person
             {
                 FirstName = "Amanda",
                 LastName = "Montana",
                 StartDate = Timestamp.FromDateTime(DateTime.ParseExact("1999-08-25T22:20:29.055Z", "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal)),
                 Rating = 6
             },
             new Person
             {
                 FirstName = "Steven",
                 LastName = "Sheridan",
                 StartDate = Timestamp.FromDateTime(DateTime.ParseExact("1991-11-11T22:20:29.055Z", "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal)),
                 Rating = 8
             },
             new Person
             {
                 FirstName = "Eleanor",
                 LastName = "Gampu",
                 StartDate = Timestamp.FromDateTime(DateTime.ParseExact("1996-12-09T22:20:29.055Z", "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal)),
                 Rating = 5
             },
             new Person
             {
                 FirstName = "Paul",
                 LastName = "Koenig",
                 StartDate = Timestamp.FromDateTime(DateTime.ParseExact("1981-04-20T22:20:29.055Z", "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal)),
                 Rating = 9
             },
             new Person
             {
                 FirstName = "Gabriela",
                 LastName = "Lister",
                 StartDate = Timestamp.FromDateTime(DateTime.ParseExact("1984-04-19T22:20:29.055Z", "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal)),
                 Rating = 4
             }
         }
     }));
 }
        public void GivenCache_WhenDataCachedUsingDifferentPolicies_Then_CacheDataBasedOnPolicyRules()
        {
            // Arrange
            var services = Fixture.ConfigureServices((repository, container) =>
            {
                container.AddCachePolicy(
                    c => CacheStorageConfiguratorExtensions.UseLocalMemory(c, p => p.WithNoExpiration()), "policy1");

                container.AddCachePolicy(
                    c => c.UseLocalMemory(
                        p => p.WithAbsoluteExpiration(10)), "policy2");

                container.AddTransientCache <IPeopleRepository, InMemoryPeopleRepository>(sp => repository,
                                                                                          c => c.Cache <GetPeopleRequest, IEnumerable <Person> >((s, r) => s.GetPeople(r),
                                                                                                                                                 s => s.GenerateKeyUsing(r => $"{r.NameContains}_{r.MinAge}_{r.MaxAge}"))
                                                                                          .UsePolicy("policy1"));

                container.AddTransientCache <IPeopleRepository, InMemoryPeopleRepository>(sp => repository,
                                                                                          c => c.Cache <string, int, int, IEnumerable <Person> >((s, p1, p2, p3) => s.GetPeople(p1, p2, p3),
                                                                                                                                                 s => s.GenerateKeyUsing((criteria, minAge, maxAge) => $"{criteria}_{minAge}_{maxAge}"))
                                                                                          .UsePolicy("policy2"));
            });

            services.TimeProvider.Now.Returns(new DateTime(2018, 02, 28, 12, 00, 00));

            // Act
            var request = new GetPeopleRequest
            {
                NameContains = "Joa",
                MinAge       = 20,
                MaxAge       = 25
            };

            var result1 = services.Sut.GetPeople("Jane", 20, 25);
            var result2 = services.Sut.GetPeople(request);

            services.TimeProvider.Now.Returns(new DateTime(2018, 02, 28, 12, 00, 11));

            result1 = services.Sut.GetPeople("Jane", 20, 25);
            result2 = services.Sut.GetPeople(request);

            // Assert
            Assert.Equal(2, services.Repository.GetPeopleUsingParametersCallCount);
            Assert.Equal(1, services.Repository.GetPeopleUsingRequestCallCount);

            Assert.Collection(result1, p =>
            {
                Assert.Equal("Jane", p.Name);
                Assert.Equal(25, p.Age);
            });
            Assert.Collection(result2, p =>
            {
                Assert.Equal("Joan", p.Name);
                Assert.Equal(21, p.Age);
            });
        }
        public async Task GivenCache_WhenDataCachedUsingDifferentRegions_And_AllRegionsGetsCleared_Then_RetrieveAllValuesFromStore()
        {
            // Arrange
            var services = Fixture.ConfigureServices((repository, container) =>
            {
                container.AddTransientCache <IPeopleRepository, InMemoryPeopleRepository>(sp => repository,
                                                                                          c => c.Cache <GetPeopleRequest, IEnumerable <Person> >((s, r) => s.GetPeople(r),
                                                                                                                                                 s => s.GenerateKeyUsing(r => $"{r.NameContains}_{r.MinAge}_{r.MaxAge}"))
                                                                                          .AssignToRegion("region1"));

                container.AddTransientCache <IPeopleRepository, InMemoryPeopleRepository>(sp => repository,
                                                                                          c => c.Cache <string, int, int, IEnumerable <Person> >((s, p1, p2, p3) => s.GetPeople(p1, p2, p3),
                                                                                                                                                 s => s.GenerateKeyUsing((criteria, minAge, maxAge) => $"{criteria}_{minAge}_{maxAge}"))
                                                                                          .AssignToRegion("region2"));
            });

            // Act
            var request = new GetPeopleRequest
            {
                NameContains = "Joa",
                MinAge       = 20,
                MaxAge       = 25
            };

            var result1 = services.Sut.GetPeople("Jane", 20, 25);
            var result2 = services.Sut.GetPeople(request);

            await services.CacheSupervisor.ClearCacheAsync();

            result1 = services.Sut.GetPeople("Jane", 20, 25);
            result2 = services.Sut.GetPeople(request);

            // Assert
            Assert.Equal(2, services.Repository.GetPeopleUsingParametersCallCount);
            Assert.Equal(2, services.Repository.GetPeopleUsingRequestCallCount);

            Assert.Collection(result1, p =>
            {
                Assert.Equal("Jane", p.Name);
                Assert.Equal(25, p.Age);
            });
            Assert.Collection(result2, p =>
            {
                Assert.Equal("Joan", p.Name);
                Assert.Equal(21, p.Age);
            });
        }
        public async Task <GetPeopleResponse> GetPeople()
        {
            var request = new GetPeopleRequest();

            return(await _repository.GetPeople(request));
        }
Esempio n. 7
0
        public List <Person> Get(GetPeopleRequest request)
        {
            Data D = new Data(Db);

            return(D.GetPeopleList());
        }