예제 #1
0
        private async Task <int> GetSubjectId(string subjectName)
        {
            int subjectID;
            var subject = await _subjectService.GetByNameAsync(subjectName);

            if (subject == null)
            {
                subjectID = await _subjectService.Create(subjectName);
            }
            else
            {
                subjectID = subject.ID;
            }
            return(subjectID);
        }
        public async Task Create_WhenSubjectWasCreated_NewSubjectIsInRepository()
        {
            // Arrange
            var fakeSubjectRepository = new FakeRepository<Subject>();
            var subjectService = new SubjectService(fakeSubjectRepository);
            var subject = new Subject { Name= "Math" };

            // Act
            var id = await subjectService.Create(subject.Name);
            var allSubjects = await subjectService.GetAll();

            // Assert
            Assert.True(id > 0);
            Assert.Equal(1, allSubjects.Count);
        }
예제 #3
0
        public async Task Create_ReturnsNewSubject()
        {
            //Arrange
            var subject = AutoFaker.Generate <Subject>();
            var userId  = AutoFaker.Generate <int>();

            _askmeRepository.Setup(x => x.AddSubject(It.IsAny <Subject>(), It.IsAny <int>()))
            .ReturnsAsync(subject);

            //Act
            var result = await _sut.Create(subject, userId);

            //Assert
            result.Should().BeOfType <Subject>();
            result.Should().BeEquivalentTo(subject);
        }
예제 #4
0
 private async void Save()
 {
     if (SubjectContext.Validate())
     {
         if (IsEdit)
         {
             if (await SubjectService.Update(Subject.Id, Model))
             {
                 Dialog.Close(DialogResult.Ok(true));
             }
         }
         else
         {
             if (await SubjectService.Create(Model))
             {
                 Dialog.Close(DialogResult.Ok(true));
             }
         }
     }
 }
        public async Task Create_WhenThreeSubjectsWereCreated_NewThreeSubjectsAreInRepository()
        {
            // Arrange
            var fakeSubjectRepository = new FakeRepository<Subject>();
            var subjectService = new SubjectService(fakeSubjectRepository);
            List<Subject> subjects = new List<Subject>() {
                new Subject { Name = "Math"},
                new Subject { Name = "Chemistry"},
                new Subject { Name =  "PE"}
            };
            
            // Act
            foreach (var subject in subjects)
            {
                await subjectService.Create(subject.Name);
            }
            var allSubjects = await subjectService.GetAll();

            // Assert
            Assert.Equal(3, allSubjects.Count);
        }
        public async Task GetByIdAsync_FindSubjectInRepository()
        {
            // Arrange
            var fakeSubjectRepository = new FakeRepository<Subject>();
            var subjectService = new SubjectService(fakeSubjectRepository);
            var expectedSubjectName = "Math";
            List<Subject> subjects = new List<Subject>() {
                new Subject { Name = "Math"},
                new Subject { Name = "Chemistry"},
                new Subject { Name =  "PE"}
            };
            
            // Act
            foreach (var subject in subjects)
            {
                await subjectService.Create(subject.Name);
            }
            var result  = await subjectService.GetByNameAsync(expectedSubjectName);

            // Assert
            Assert.True(result.ID > 0);            
            Assert.Equal(expectedSubjectName, result.Name);
        }
        public async Task Create()
        {
            var subject = await CreateModel();

            await _subjectService.Create(subject);
        }