Exemplo n.º 1
0
        public async Task GetMemberById_WithZeroAndNegativeId_ReturnsError(int id)
        {
            //Arrange
            var mockContext = new MockContext<IRepository<Member>>();
            membersRepo = new FakeMemberRepository(mockContext);
            var controller = new MembersController(new DivineRepositories(null, lookupRepo, membersRepo, null), logger, null, null);

            //Act
            var result = await controller.Get(id);

            //Assert
            mockContext.Assert(m => m.GetByIdAsync(The<int>.IsAnyValue), Invoked.Never);
            Assert.NotNull(result);
            Assert.Equal(result.StatusCode, (int)HttpStatusCode.BadRequest);
            Assert.IsType<string>(result.Value);
            Assert.Contains("error", result.Value.ToString(), StringComparison.OrdinalIgnoreCase);
        }
Exemplo n.º 2
0
        public async Task Get_ReturnsBadRequest()
        {
            //Arrange
            var mockContext = new MockContext<IRepository<Member>>();
            membersRepo = new FakeMemberRepository(mockContext);
            var controller = new MembersController(new DivineRepositories(null, lookupRepo, membersRepo, null), logger, null, null);
            mockContext.Arrange(x => (x.GetAllAsync())).Throws(() => new NullReferenceException("null Data"));

            //Act
            var result = await controller.Get();

            //Assert
            Assert.NotNull(result);
            Assert.Equal(result.StatusCode , (int) HttpStatusCode.BadRequest);
            Assert.IsType<string>(result.Value);
            Assert.Contains("error",result.Value.ToString(),  StringComparison.OrdinalIgnoreCase);
        }
Exemplo n.º 3
0
        public async Task Get_ReturnsNoException()
        {
            //Arrange
            var mockContext = new MockContext<IRepository<Member>>();
            membersRepo = new FakeMemberRepository(mockContext);
            var controller = new MembersController(new DivineRepositories(null, lookupRepo, membersRepo, null),logger, null, null);
            var data = new List<Member> { new Member { Id = 1 } }.AsQueryable();
            mockContext.Arrange(x => (x.GetAllAsync())).Returns(Task.FromResult(data));

            //ACT
            var result = await controller.Get();

            //Assert
            Assert.NotNull(result);
            Assert.IsType<List<Member>>(result.Value);
            Assert.Equal(data.Count(), ((List<Member>)result.Value).Count());


        }
Exemplo n.º 4
0
        public async Task GetMemberById_WithValidPoisitiveId_ReturnsSuccess()
        {
            //Arrange
            var mockContext = new MockContext<IRepository<Member>>();
            membersRepo = new FakeMemberRepository(mockContext);
            var controller = new MembersController(new DivineRepositories(null, lookupRepo, membersRepo, null), logger, null, null);
            mockContext.Arrange(m => m.GetByIdAsync(The<int>.IsAnyValue)).Returns(Task.FromResult(new Member { Id=1 }));
            var id = 1;

            //Act
            var result = await controller.Get(id);

            //Assert
            mockContext.Assert(m => m.GetByIdAsync(id), Invoked.Once);
            Assert.NotNull(result);
            Assert.IsType<Member>(result.Value);
            Assert.Equal(((Member)result.Value).Id, id);
        }