Exemplo n.º 1
0
        public async Task Add__Adding_Not_Existed_RozkladUser()
        {
            var expectedRozkladUser = new RozkladUser();

            expectedRozkladUser.FacultyGroups.AddRange(GetMockGroupList1());
            expectedRozkladUser.IsDeleted = false;


            await using (var context = new NpuRozkladContext(GetContextOptions("add1")))
            {
                var repo = new RozkladUsersDao(context, Mock.Of <IFacultyGroupsProvider>(), StubCache);

                await repo.Add(expectedRozkladUser);
            }


            RozkladUserWrapper actualRozkladUserWrapper;

            await using (var context = new NpuRozkladContext(GetContextOptions("add1")))
            {
                actualRozkladUserWrapper = await context.RozkladUserWrappers.SingleAsync();
            }

            Assert.AreEqual(expectedRozkladUser.Guid, actualRozkladUserWrapper.Guid);
            Assert.AreEqual(expectedRozkladUser.IsDeleted, actualRozkladUserWrapper.IsDeleted);
            Assert.AreEqual(expectedRozkladUser.FacultyGroups.Count, actualRozkladUserWrapper.FacultyGroupsTypeIds.Count);

            foreach (var group in expectedRozkladUser.FacultyGroups)
            {
                Assert.Contains(group.TypeId, actualRozkladUserWrapper.FacultyGroupsTypeIds);
            }
        }
Exemplo n.º 2
0
        public async Task Delete__Deleting_Existing_RozkladUser__Should_Change_IsDeleted_Property()
        {
            var expectedRozkladUser = new RozkladUser();

            expectedRozkladUser.FacultyGroups.AddRange(GetMockGroupList1());
            expectedRozkladUser.IsDeleted = false;

            await using (var context = new NpuRozkladContext(GetContextOptions("delete1")))
            {
                await context.AddAsync(new RozkladUserWrapper(expectedRozkladUser));

                await context.SaveChangesAsync();
            }

            await using (var context = new NpuRozkladContext(GetContextOptions("delete1")))
            {
                var repo = new RozkladUsersDao(context, Mock.Of <IFacultyGroupsProvider>(), StubCache);
                await repo.Delete(expectedRozkladUser);
            }

            RozkladUserWrapper actualRozkladUserWrapper;

            await using (var context = new NpuRozkladContext(GetContextOptions("delete1")))
            {
                actualRozkladUserWrapper = await context.RozkladUserWrappers.SingleAsync();

                Assert.AreEqual(1, context.RozkladUserWrappers.Count());
            }

            Assert.AreEqual(expectedRozkladUser.Guid, actualRozkladUserWrapper.Guid);
            Assert.True(actualRozkladUserWrapper.IsDeleted);
            Assert.AreEqual(0, actualRozkladUserWrapper.FacultyGroupsTypeIds.Count);
        }
Exemplo n.º 3
0
        public async Task Find__Should_Find_RozkladUser_And_Fill_Groups_List_From_String()
        {
            var expectedRozkladUser = new RozkladUser();

            expectedRozkladUser.FacultyGroups.AddRange(GetMockGroupList1());
            expectedRozkladUser.IsDeleted = false;

            await using (var context = new NpuRozkladContext(GetContextOptions("find1")))
            {
                await context.AddAsync(new RozkladUserWrapper(expectedRozkladUser));

                await context.SaveChangesAsync();
            }

            var providerMock = new Mock <IFacultyGroupsProvider>();

            providerMock.Setup(p => p.GetFacultyGroups())
            .ReturnsAsync(GetMockGroupList1());

            RozkladUser actualRozkladUser = null;

            await using (var context = new NpuRozkladContext(GetContextOptions("find1")))
            {
                var repo = new RozkladUsersDao(context, providerMock.Object, StubCache);
                actualRozkladUser = await repo.Find(expectedRozkladUser.Guid);
            }

            Assert.NotNull(actualRozkladUser);
            Assert.AreEqual(expectedRozkladUser.Guid, actualRozkladUser.Guid);
            Assert.AreEqual(expectedRozkladUser.IsDeleted, actualRozkladUser.IsDeleted);

            foreach (var expectedFacultyGroup in expectedRozkladUser.FacultyGroups)
            {
                var actualFacultyGroup =
                    actualRozkladUser.FacultyGroups.FirstOrDefault(
                        g => g.TypeId == expectedFacultyGroup.TypeId);

                Assert.NotNull(actualRozkladUser);
                Assert.AreEqual(expectedFacultyGroup.Faculty, actualFacultyGroup.Faculty);
                Assert.AreEqual(expectedFacultyGroup.Name, actualFacultyGroup.Name);
            }
        }
Exemplo n.º 4
0
        public async Task Update__Updating_Existed_RozkladUser()
        {
            var expectedRozkladUser = new RozkladUser();

            expectedRozkladUser.FacultyGroups.AddRange(GetMockGroupList1());
            expectedRozkladUser.IsDeleted = false;

            await using (var context = new NpuRozkladContext(GetContextOptions("update1")))
            {
                await context.AddAsync(new RozkladUserWrapper(expectedRozkladUser));

                await context.SaveChangesAsync();
            }

            await using (var context = new NpuRozkladContext(GetContextOptions("update1")))
            {
                var repo = new RozkladUsersDao(context, Mock.Of <IFacultyGroupsProvider>(), StubCache);

                expectedRozkladUser.FacultyGroups.Add(new Group("c", "C", expectedRozkladUser.FacultyGroups.First().Faculty));
                await repo.Update(expectedRozkladUser);
            }

            RozkladUserWrapper actualRozkladUserWrapper;

            await using (var context = new NpuRozkladContext(GetContextOptions("update1")))
            {
                actualRozkladUserWrapper = await context.RozkladUserWrappers.SingleAsync();

                Assert.AreEqual(1, context.RozkladUserWrappers.Count());
            }

            Assert.AreEqual(expectedRozkladUser.Guid, actualRozkladUserWrapper.Guid);
            Assert.False(actualRozkladUserWrapper.IsDeleted);
            Assert.AreEqual(expectedRozkladUser.FacultyGroups.Count, actualRozkladUserWrapper.FacultyGroupsTypeIds.Count);

            foreach (var group in expectedRozkladUser.FacultyGroups)
            {
                Assert.Contains(group.TypeId, actualRozkladUserWrapper.FacultyGroupsTypeIds);
            }
        }