Exemplo n.º 1
0
        public async Task EarnPoints_ShouldReturn_Ok(string customerUsername, int pointsToAdd, MembershipPointsType membershipPointsType)
        {
            var readModelContext = (ReadModelDbContext)_fixture.Services.GetService(typeof(ReadModelDbContext));

            var customer = (await readModelContext.Customers.FirstOrDefaultAsync(c => c.Username == customerUsername));
            var member   = (await readModelContext.Memberships.FirstOrDefaultAsync(m => m.CustomerId == customer.Id));

            var currentPoint   = member.TotalPoints;
            var currentVersion = member.Version;
            var request        = new EarnPointsAggregateMembershipCommand(member.Id, membershipPointsType, pointsToAdd);
            var response       = await _client.PutRequestAsStringContent("/Membership/points", request);

            response.EnsureSuccessStatusCode();
            var content = await response.Content.ReadAsStringAsync();

            _output.WriteLine(content);

            var jsonObject = JObject.Parse(content);

            jsonObject.ShouldContainKeyAndValue("totalPoints", pointsToAdd + (int)currentPoint);
            jsonObject.ShouldContainKey("version");
            var newVersion = (int)jsonObject.GetValue("version");

            newVersion.ShouldBeGreaterThan(currentVersion);
        }
Exemplo n.º 2
0
        public async Task EarnPointsMoreThan100_ShouldEarnRewards_Return_Ok()
        {
            var readModelContext = (ReadModelDbContext)_fixture.Services.GetService(typeof(ReadModelDbContext));
            var customerUsername = "******";

            var customer = (await readModelContext.Customers.FirstOrDefaultAsync(c => c.Username == customerUsername));
            var member   = (await readModelContext.Memberships.FirstOrDefaultAsync(m => m.CustomerId == customer.Id));

            var pointsToAdd = 150;
            var request1    = new EarnPointsAggregateMembershipCommand(member.Id, MembershipPointsType.Movie, pointsToAdd);
            var request2    = new EarnPointsAggregateMembershipCommand(member.Id, MembershipPointsType.Music, pointsToAdd);
            await _client.PutRequestAsStringContent("/Membership/points", request1);

            var response2 = await _client.PutRequestAsStringContent("/Membership/points", request2);

            response2.EnsureSuccessStatusCode();
            var content = await response2.Content.ReadAsStringAsync();

            _output.WriteLine(content);

            var jsonObject = JObject.Parse(content);

            jsonObject.ShouldContainKey("totalPoints");
            jsonObject.ShouldContainKey("version");

            var rewards = await readModelContext.Rewards.Where(r => r.CustomerId == member.CustomerId).ToListAsync();

            _output.WriteLine($"Rewards count: {rewards.Count()}");
            rewards.Count().ShouldBe(2);
            foreach (var r in rewards)
            {
                _output.WriteLine($"{r.CustomerId}: {r.RewardType} at {r.EarnedAt}");
            }
        }
Exemplo n.º 3
0
        public async Task EarnPoints_ShouldUpdateReporting_Return_Ok()
        {
            var readModelContext = (ReadModelDbContext)_fixture.Services.GetService(typeof(ReadModelDbContext));
            var customerUsername = "******";

            var customer    = (await readModelContext.Customers.FirstOrDefaultAsync(c => c.Username == customerUsername));
            var member      = (await readModelContext.Memberships.FirstOrDefaultAsync(m => m.CustomerId == customer.Id));
            var pointsToAdd = 150;
            var req         = new EarnPointsAggregateMembershipCommand(member.Id, MembershipPointsType.Movie, pointsToAdd);
            await _client.PutRequestAsStringContent("/Membership/points", req);

            var reportingContext = (ReportingReadModelDbContext)_fixture.Services.GetService(typeof(ReportingReadModelDbContext));
            var memberReporting  = await reportingContext.MembershipPointsReporting.FirstOrDefaultAsync(m => m.MembershipId == member.Id);

            memberReporting.ShouldNotBeNull();
            _output.WriteLine($"Member: {memberReporting.MembershipId} with {memberReporting.Username} has {memberReporting.TotalPoints} earned {memberReporting.PointsEarnedTime} times");

            memberReporting.TotalPoints.ShouldBe(pointsToAdd);
            memberReporting.PointsEarnedTime.ShouldBe(1);
            memberReporting.Username.ShouldBe(customerUsername);
        }