public async Task TestB_UserNotOwnCollection()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

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

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

            var request = new DeleteCollectionC(Guid.Parse("82c3a0d1-a73c-41e2-a8f3-ef525e5f0ffa"), "9a4e1d79-d64e-4ec4-85e5-53bdef5043f4");

            var actionResponse = await service.Send(request);

            Assert.False(actionResponse.IsSucceed);

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(6, await db.Collections.CountAsync());
            }
        }
        public async Task TestC()
        {
            var mock = new MockDataV3();

            mock.Reset();

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

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

            var updateFlashcardProgressC = new UpdateFlashcardProgressC(Guid.Parse("9884d783-427d-45d4-a1df-facaf81729f5"), FlashcardProgress.Know, "9a4e1d79-d64e-4ec4-85e5-53bdef5043f4");

            var actionResponse = await mediator.Send(updateFlashcardProgressC);

            using (var db = MockDatabaseFactory.Build())
            {
                var flashcardProgressModel = await db.FlashcardProgresses.FirstOrDefaultAsync(e => e.Id == Guid.Parse("9884d783-427d-45d4-a1df-facaf81729f5"));

                Assert.Equal(1, flashcardProgressModel.CorrectInRow);
                Assert.Equal(DateTime.Now.Date.AddDays(1), flashcardProgressModel.PracticeDate);
            }
        }
Exemplo n.º 3
0
        public async Task TestB_FlashcardNotExists()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

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

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

            var deleteFlashcardC = new DeleteFlashcardC(Guid.Parse("00003ba0-1396-428f-adb7-d7ab972459eb"), "9a4e1d79-d64e-4ec4-85e5-53bdef5043f4");

            var actionResult = await mediator.Send(deleteFlashcardC);

            Assert.False(actionResult.IsSucceed);

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(2, await db.Flashcards.CountAsync());
            }
        }
Exemplo n.º 4
0
        public async Task TestC_UserNotOwnFlashcard()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

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

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

            var deleteFlashcardC = new DeleteFlashcardC(Guid.Parse("6aa83ba0-1396-428f-adb7-d7ab972459eb"), "fcabcb46-12dc-4013-bc92-6f00aae903b4");

            var actionResult = await mediator.Send(deleteFlashcardC);

            Assert.False(actionResult.IsSucceed);

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(2, await db.Flashcards.CountAsync());
            }
        }
Exemplo n.º 5
0
        public async Task TestC_UserNotOwnCollection()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

            var serviceProvider = new ServiceCollection()
                                  .AddTransient <ICollectionRepo, CollectionRepo>()
                                  .AddTransient <IFlashcardBuilder, FlashcardBuilder>()
                                  .AddTransient <IFlashcardRepo, FlashcardRepo>()
                                  .AddDbContext <AppDbContext>(options => options.UseSqlServer(MockDatabaseFactory.DbMockConnectionString))
                                  .AddMediatR(typeof(MediatREntryPoint).Assembly)
                                  .BuildServiceProvider();

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

            var inputModel = new FlashcardInsertModel()
            {
                CollectionId = Guid.Parse("82c3a0d1-a73c-41e2-a8f3-ef525e5f0ffa"),
                Foreign      = "Foreign ok",
                Native       = "Native ok"
            };

            var insertFlashcardC = new InsertFlashcardC(inputModel, "9a4e1d79-d64e-4ec4-85e5-53bdef5043f4");

            var actionResult = await service.Send(insertFlashcardC, new System.Threading.CancellationToken());

            Assert.False(actionResult.IsSucceed);

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(2, await db.Flashcards.CountAsync());
                Assert.Equal(4, await db.FlashcardProgresses.CountAsync());
            }
        }
        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);
            }
        }
Exemplo n.º 7
0
        public async Task TestC_UserDoNotOwnFlashcard()
        {
            var mocker = new MockDataV5();

            mocker.Reset();

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

            var insertDTO = new FlashcardUpdateModel()
            {
                Id      = Guid.Parse("691de3f1-8117-465f-b8d9-7cfcefc372fe"),
                Foreign = "foreign new",
                Native  = "native new"
            };

            var response = await _client.PutAsync("api/flashcard/update", new StringContent(JsonConvert.SerializeObject(insertDTO), Encoding.UTF8, "application/json"));

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

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal("Foreign 4", (await db.Flashcards.FirstOrDefaultAsync(e => e.Id == Guid.Parse("691de3f1-8117-465f-b8d9-7cfcefc372fe"))).Foreign);
                Assert.Equal("Native 4", (await db.Flashcards.FirstOrDefaultAsync(e => e.Id == Guid.Parse("691de3f1-8117-465f-b8d9-7cfcefc372fe"))).Native);
            }
        }
        public async Task TestE()
        {
            var mocker = new MockDataV6();

            mocker.Reset();

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


            var response = await _client.GetAsync("api/practice/updateflashcardprogress/9dccbe2b-fd54-42e7-8f35-c0fba62855f7/3");

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

            var response2 = await _client.GetAsync("api/practice/updateflashcardprogress/9dccbe2b-fd54-42e7-8f35-c0fba62855f7/3");

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

            await Task.Delay(1000 * 5);

            using (var db = MockDatabaseFactory.Build())
            {
                var flashcardProgressModel = await db.FlashcardProgresses.FirstOrDefaultAsync(e => e.Id == Guid.Parse("9dccbe2b-fd54-42e7-8f35-c0fba62855f7"));

                Assert.Equal(3, flashcardProgressModel.CorrectInRow);
                Assert.Equal(DateTime.Now.Date, flashcardProgressModel.PracticeDate);
            }
        }
        public async Task TestA()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

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

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

            var request = new DeleteCollectionC(Guid.Parse("d30c8f79-291b-4532-8f22-b693e61d6bb5"), "9a4e1d79-d64e-4ec4-85e5-53bdef5043f4");

            var actionResponse = await service.Send(request);

            Assert.True(actionResponse.IsSucceed);

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(5, await db.Collections.CountAsync());
            }
        }
Exemplo n.º 10
0
        public async Task TestB_NoNamePassed()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

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

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

            var result = await service.Send(new InsertCollectionC(new CollectionInsertModel()
            {
                Name = ""
            }, "9a4e1d79-d64e-4ec4-85e5-53bdef5043f4"));

            Assert.False(result.IsSucceed);

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(6, await db.Collections.CountAsync());
            }
        }
Exemplo n.º 11
0
 public void Reset()
 {
     using (var db = MockDatabaseFactory.Build())
     {
         db.RemoveRange(db.Collections);
         db.SaveChanges();
         db.AddRange(Collections);
         db.SaveChanges();
     }
 }
Exemplo n.º 12
0
        public async Task TestC_UserNotOwnCollection()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

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

            var response = await _client.DeleteAsync("api/collection/delete/82c3a0d1-a73c-41e2-a8f3-ef525e5f0ffa");

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

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(6, await db.Collections.CountAsync());
            }
        }
Exemplo n.º 13
0
        public static void Mock(int flashcardQuantity)
        {
            var collectionModel = new CollectionModel()
            {
                Id = Guid.Parse("a36d18ca-a912-49da-bfc2-2a41b1d87e7c"), Name = "collection name", UserId = "be723b31-56b0-4b6d-a7c3-b0d979ed4d00"
            };

            collectionModel.FlashcardModels = new List <FlashcardModel>();

            for (int i = 1; i <= flashcardQuantity; i++)
            {
                collectionModel.FlashcardModels.Add(new FlashcardModel()
                {
                    Foreign = $"Foreign {i}",
                    Native  = $"Native {i}",
                    FlashcardProgressModels = new List <FlashcardProgressModel>()
                    {
                        new FlashcardProgressModel()
                        {
                            PracticeDate      = DateTime.Now.Date.AddDays((new Random()).Next(-5, 100)),
                            CorrectInRow      = (new Random()).Next(0, 10),
                            PracticeDirection = Entities.Enums.PracticeDirection.ForeignToNative
                        },
                        new FlashcardProgressModel()
                        {
                            PracticeDate      = DateTime.Now.Date.AddDays((new Random()).Next(-5, 100)),
                            CorrectInRow      = (new Random()).Next(0, 10),
                            PracticeDirection = Entities.Enums.PracticeDirection.NativeToForeign
                        }
                    }
                });
            }

            using (var db = MockDatabaseFactory.Build())
            {
                db.Collections.RemoveRange(db.Collections);

                db.SaveChanges();

                db.Collections.Add(collectionModel);

                db.SaveChanges();
            }
        }
Exemplo n.º 14
0
        public void Reset()
        {
            using (var db = MockDatabaseFactory.Build())
            {
                db.RemoveRange(db.Flashcards);
                db.SaveChanges();
                db.RemoveRange(db.Collections);
                db.SaveChanges();
                db.RemoveRange(db.StatsUserModels);
                db.SaveChanges();

                db.AddRange(Collections);
                db.SaveChanges();
                db.AddRange(Flashcards);
                db.SaveChanges();
                db.AddRange(StatsUser);
                db.SaveChanges();
            }
        }
Exemplo n.º 15
0
        public async Task TestB_NameExists()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

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

            var inputDTO = new CollectionInsertModel()
            {
                Name = "User 1 Name 1"
            };

            var response = await _client.PostAsync("api/collection/insert", new StringContent(JsonConvert.SerializeObject(inputDTO), Encoding.UTF8, "application/json"));

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

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(6, await db.Collections.CountAsync());
            }
        }
Exemplo n.º 16
0
        public async Task TestB_UserNotOwnCollection()
        {
            var mocker = new MockDataV3();

            mocker.Reset();

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

            var inputDTO = new CollectionUpdateModel()
            {
                Id   = Guid.Parse("82c3a0d1-a73c-41e2-a8f3-ef525e5f0ffa"),
                Name = "name"
            };

            var response = await _client.PutAsync("api/collection/update", new StringContent(JsonConvert.SerializeObject(inputDTO), Encoding.UTF8, "application/json"));

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

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal("User 2 Name 2", db.Collections.FirstOrDefault(e => e.Id == Guid.Parse("82c3a0d1-a73c-41e2-a8f3-ef525e5f0ffa")).Name);
            }
        }
Exemplo n.º 17
0
 private IFlashcardProgressRepo BuildUnitForTests() =>
 new FlashcardProgressRepo(MockDatabaseFactory.Build());
Exemplo n.º 18
0
 private GetCollectionsListH BuildHandlerForTests() =>
 new GetCollectionsListH(
     new CollectionRepo(MockDatabaseFactory.Build()));