Example #1
0
        public async Task DeleteActivityAsync_CheckErrorOccured(int id)
        {
            using var context = PrepareData.GetDbContext(); var service = new ActivitiesService(context);
            var value = await service.DeleteActivityAsync(id, null);

            Assert.True(value.IsLeft);
        }
Example #2
0
        private async Task DeleteElement <T>() where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var result = await service.RemoveKey(10000, null);

            Assert.True(result.IsLeft);
        }
Example #3
0
        public async Task CreateActivityAsync_CorrectUpdateOnContext(
            string teacher, string room, string subject, string classGroup, int slot)
        {
            using var context = PrepareData.GetDbContext(); var activityDTO = new ActivityCreateDTO()
            {
                ClassGroup = classGroup,
                Room       = room,
                Slot       = slot,
                Subject    = subject,
                Teacher    = teacher
            };
            var service = new ActivitiesService(context);
            var value   = await service.CreateActivityAsync(activityDTO);

            var activity = GetActivities(context).FirstOrDefault(
                a => a.Teacher.Name == teacher &&
                a.Subject.Name == subject &&
                a.Slot.Index == slot &&
                a.Room.Name == room &&
                a.ClassGroup.Name == classGroup
                );

            Assert.True(value.IsRight);
            Assert.NotNull(activity);
        }
Example #4
0
        private async Task GetDictionaryElementAsync <T>() where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var result = await service.GetDictionaryElementAsync(2137);

            Assert.True(result.IsLeft);
        }
Example #5
0
        public async Task GetActivityByGroupAsync_GiveIncorrectId_GetError(int id)
        {
            using var context = PrepareData.GetDbContext(); var service = new ActivitiesService(context);
            var test = await service.GetActivity(id);

            Assert.True(test.IsLeft);
        }
Example #6
0
        public async Task EditActivityAsync_CorrectUpdateOnContext(
            string teacher, string room, string subject, string classGroup)
        {
            using var context = PrepareData.GetDbContext(); var activity = context.Activities.Include(a => a.Slot).FirstOrDefault();
            int id          = activity.Id;
            int slot        = activity.Slot.Index;
            var activityDTO = new ActivityEditDTO()
            {
                Id         = id,
                ClassGroup = classGroup,
                Room       = room,
                Slot       = slot,
                Subject    = subject,
                Teacher    = teacher
            };
            var service = new ActivitiesService(context);
            var value   = await service.EditActivityAsync(activity.Id, activityDTO);

            var activityToCheck = GetActivities(context).FirstOrDefault(
                a =>
                a.Id == id &&
                a.Teacher.Name == teacher &&
                a.Room.Name == room &&
                a.Subject.Name == subject &&
                a.ClassGroup.Name == classGroup
                );

            Assert.True(value.IsRight);
            Assert.NotNull(activityToCheck);
        }
Example #7
0
        public async Task EditActivityAsync_WhenActivityDTOIsNull_CheckErrorOccured()
        {
            using var context = PrepareData.GetDbContext(); var service = new ActivitiesService(context);
            var value = await service.EditActivityAsync(1, null);

            Assert.True(value.IsLeft);
        }
Example #8
0
        public async Task CreateActivityAsync_WhenOneOfValuesIsOccupied_CheckErrorOccured(
            string teacher, string room, string subject, string classGroup, int slot)
        {
            using var context = PrepareData.GetDbContext(); var service = new ActivitiesService(context);
            var value = await service.CreateActivityAsync(GetDTOToCreate(teacher, room, subject, classGroup, slot));

            Assert.True(value.IsLeft);
        }
Example #9
0
        public async Task EditActivityAsync_WhenOneOfValuesIsOccupied_CheckErrorOccured(
            string teacher, string room, string subject, string classGroup)
        {
            using var context = PrepareData.GetDbContext(); var activityDTO = GetDTOToEdit(teacher, room, subject, classGroup, context);
            var service = new ActivitiesService(context);
            var value   = await service.EditActivityAsync(activityDTO.Id, activityDTO);

            Assert.True(value.IsLeft);
        }
Example #10
0
        private async Task UpdateKey <T>() where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var dictionaryElement = new DictionaryElementEditDTO()
            {
                Id = 1000
            };
            var result = await service.UpdateKey(dictionaryElement);

            Assert.True(result.IsLeft);
        }
Example #11
0
        private async Task GetDictionaryGenericAsync <T>() where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            int size = context.Set <T>().Count();
            var dictionaryIndexDTO = await service.GetDictionaryAsync();

            Assert.True(dictionaryIndexDTO.IsRight);
            dictionaryIndexDTO.IfRight(r => {
                Assert.Equal(size, r.Count());
            });
        }
Example #12
0
        private async Task RemoveKey <T>(string name) where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var element = context.Set <T>().AsNoTracking().FirstOrDefault(e => e.Name == name);
            var result  = await service.RemoveKey(element.Id, element.Timestamp);

            Assert.True(result.IsRight);
            var value = context.Set <T>().AsNoTracking().FirstOrDefault(e => e.Id == element.Id);

            Assert.Null(value);
        }
Example #13
0
        private async Task AddKey <T>(string name) where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var dictionaryElement = new DictionaryElementCreateDTO()
            {
                Name = name
            };
            var result = await service.AddKey(dictionaryElement);

            Assert.True(result.IsLeft);
        }
Example #14
0
        private async Task GetDictionaryElementGenericAsync <T>(string name) where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var dictionaryElement    = context.Set <T>().FirstOrDefault(e => e.Name == name);
            var dictionaryElementDTO = await service.GetDictionaryElementAsync(dictionaryElement.Id);

            Assert.True(dictionaryElementDTO.IsRight);
            dictionaryElementDTO.IfRight(r => {
                Assert.Equal(dictionaryElement.Id, r.Id);
                Assert.Equal(dictionaryElement.Name, r.Name);
            });
        }
        public void GetScheduleByTeacher_ReturnCorrectDTO(string teacher, string title, int index)
        {
            using var context = PrepareData.GetDbContext(); var service = new ScheduleService(context);
            var scheduleDTO = service.GetScheduleByTeacher(teacher);

            Assert.True(scheduleDTO.IsRight);
            scheduleDTO.IfRight(r => {
                Assert.Equal(title, r.Slots[index].Title);
                Assert.Equal("teachers", r.Type);
                Assert.Equal(teacher, r.Name);
            });
        }
Example #16
0
        private async Task UpdateKey <T>(string name, string newName) where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var element           = context.Set <T>().FirstOrDefault(e => e.Name == name);
            var dictionaryElement = new DictionaryElementEditDTO()
            {
                Id   = element.Id,
                Name = newName
            };
            var result = await service.UpdateKey(dictionaryElement);

            Assert.True(result.IsLeft);
        }
Example #17
0
        private async Task AddKeyGeneric <T>() where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var dictionaryElement = new DictionaryElementCreateDTO()
            {
                Name = "elo"
            };
            var result = await service.AddKey(dictionaryElement);

            Assert.True(result.IsRight);
            var value = context.Set <T>().FirstOrDefault(e => e.Name == dictionaryElement.Name);

            Assert.NotNull(value);
        }
Example #18
0
        private async Task UpdateKey <T>(string name) where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var element           = context.Set <T>().AsNoTracking().FirstOrDefault(e => e.Name == name);
            var dictionaryElement = new DictionaryElementEditDTO()
            {
                Id   = element.Id,
                Name = "elo"
            };
            var result = await service.UpdateKey(dictionaryElement);

            Assert.True(result.IsRight);
            var value = context.Set <T>().AsNoTracking().FirstOrDefault(e => e.Id == element.Id);

            Assert.Equal("elo", value.Name);
        }
Example #19
0
        public async Task DeleteActivityAsync_CorrectUpdateOnContext(
            int slot, string classgroup, string teacher, string room)
        {
            using var context = PrepareData.GetDbContext(); var activityToDelete = GetActivities(context).FirstOrDefault(
                a => a.Slot.Index == slot &&
                a.Room.Name == room &&
                a.Teacher.Name == teacher &&
                a.ClassGroup.Name == classgroup
                );
            var service = new ActivitiesService(context);
            var value   = await service.DeleteActivityAsync(activityToDelete.Id, activityToDelete.Timestamp);

            var activity = context.Activities.FirstOrDefault(a => a.Id == activityToDelete.Id);

            Assert.Null(activity);
            Assert.True(value.IsRight);
        }
        public async Task GetActivityAsync_ReturnCorrectDTO()
        {
            using var context = PrepareData.GetDbContext();
            var service     = new ActivitiesService(context);
            var activity    = GetActivities(context).FirstOrDefault();
            var activityDTO = await service.GetActivity(activity.Id);

            Assert.True(activityDTO.IsRight);
            activityDTO.IfRight(r => {
                Assert.Equal(activity.Id, r.Id);
                Assert.Equal(activity.Room.Name, r.Room);
                Assert.Equal(activity.Slot.Index, r.Slot);
                Assert.Equal(activity.Subject.Name, r.Subject);
                Assert.Equal(activity.Teacher.Name, r.Teacher);
                Assert.Equal(activity.ClassGroup.Name, r.ClassGroup);
            });
        }