コード例 #1
0
        public async Task TestB()
        {
            var mock = new MockDataV4();

            mock.Reset();

            var serviceProvider = new ServiceCollection()
                                  .AddTransient <IStatsUserRepo, StatsUserRepo>()
                                  .AddDbContext <AppDbContext>(options => options.UseSqlServer(MockDatabaseFactory.DbMockConnectionString))
                                  .AddMediatR(typeof(MediatREntryPoint).Assembly)
                                  .BuildServiceProvider();

            var mediator = serviceProvider.GetService <IMediator>();

            var command = new IncrementStatsUserC("a071553b-70e4-4998-aac2-37883d2d83ab");

            var actionResponse = await mediator.Send(command);

            Assert.True(actionResponse.IsSucceed);

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(4, await db.StatsUserModels.CountAsync());
                Assert.Equal(3, db.StatsUserModels.FirstOrDefault(e => e.Id == Guid.Parse("d28e4728-1082-477d-b9c8-be81aa165efb")).FlashcardsTurnOverCount);
                Assert.Equal(2, db.StatsUserModels.FirstOrDefault(e => e.Id == Guid.Parse("1d43f5dd-ef30-45e1-a99d-d3183807b953")).FlashcardsTurnOverCount);
                Assert.Equal(1, db.StatsUserModels.FirstOrDefault(e => e.UserId == "a071553b-70e4-4998-aac2-37883d2d83ab" && e.Day == DateTime.Now.Date).FlashcardsTurnOverCount);
            }
        }
コード例 #2
0
        public async Task TestA()
        {
            var mock = new MockDataV4();

            mock.Reset();

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjlhNGUxZDc5LWQ2NGUtNGVjNC04NWU1LTUzYmRlZjUwNDNmNCIsIm5iZiI6MTYxOTc2OTYzOCwiZXhwIjoxNjE5ODU2MDM4LCJpc3MiOiJhIn0.tohmUFgbnXqaMoehSX9i-p_F6vpdoziu9Jz5XgM1N1k");

            var response = await _client.GetAsync("api/statistics/getuserweekstats");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var responseModel = JsonConvert.DeserializeObject <StatsUserTurnOverWeekGetModel>(await response.Content.ReadAsStringAsync());

            Assert.Equal(3, responseModel.TodayCount);
            Assert.Equal(DateTime.Now.Date.DayOfWeek.ToString().Substring(0, 3), responseModel.TodayDate);

            Assert.Equal(2, responseModel.YesterdayCount);

            Assert.Equal(0, responseModel.ThreeDayBeforeCount);

            Assert.Equal(0, responseModel.FourDayBeforeCount);

            Assert.Equal(0, responseModel.SevenDayBeforeCount);
            Assert.Equal(DateTime.Now.Date.AddDays(-6).DayOfWeek.ToString().Substring(0, 3), responseModel.SevenDayBeforeDate);
        }