Exemple #1
0
        public async Task GetCourses_WithAFewCourses_ShouldReturnAll()
        {
            // Arrange
            this.context.Courses.Add(new Course {
                Id = 1, Name = "First course"
            });
            this.context.Courses.Add(new Course {
                Id = 2, Name = "Second course"
            });
            this.context.Courses.Add(new Course {
                Id = 3, Name = "Third course"
            });
            await this.context.SaveChangesAsync();

            this.courseRepositoryMock
            .Setup(m => m.Details())
            .Returns(this.context.Courses)
            .Verifiable();

            var service = new AdminCoursesService(this.mapper, this.courseRepositoryMock.Object);

            // Act
            var courses = await service.GetCoursesAsync <Course>();

            // Assert
            Assert.IsNotNull(courses);
            Assert.AreEqual(3, courses.Count());
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, courses.Select(c => c.Id).ToArray());
        }
Exemple #2
0
        public async Task GetCourses_WithNoCourses_ShouldReturnNone()
        {
            // Arrange
            this.courseRepositoryMock
            .Setup(m => m.Details())
            .Returns(this.context.Courses)
            .Verifiable();

            var service = new AdminCoursesService(this.mapper, this.courseRepositoryMock.Object);

            // Act
            var courses = await service.GetCoursesAsync <Course>();

            // Assert
            Assert.IsNotNull(courses);
            Assert.AreEqual(0, courses.Count());
        }