public void Add_CalledWithValidTeamId_ShouldAddMember() { var team = new Team("BD Team", Guid.NewGuid()); teamController.Add(team); var membersBeforeAdd = ((teamController.Get(team.Id) as ObjectResult).Value as Team).Members.Count; memberController.Add(team.Id, new Member("Abu Zafor", "Fagun", Guid.NewGuid())); var membersAfterAdd = ((teamController.Get(team.Id) as ObjectResult).Value as Team).Members.Count; Assert.Equal(membersAfterAdd, membersBeforeAdd + 1); }
public async Task Ok_Success() { var controller = new TeamsController(_service.Object, _mapper, _logger.Object); var result = await controller.Add(MockedTeam()); Assert.IsNotNull(result); Assert.IsInstanceOf <IActionResult>(result); Assert.IsInstanceOf <OkResult>(result); _service.Verify(x => x.AddTeamAsync(It.IsAny <Team>()), Times.Once); _logger.Verify(x => x.Log(LogLevel.Debug, It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Once); _logger.Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Never); }
public void Add_Should_AddItem() { var previousTeamCount = (((controller.GetAll() as OkObjectResult).Value) as IList <Team>).Count; var team = new Team("New team"); controller.Add(team); var currentTeamCount = (((controller.GetAll() as OkObjectResult).Value) as IList <Team>).Count; Assert.Equal(currentTeamCount, previousTeamCount + 1); }
public async Task ServiceFail_Return500() { _service.Setup(x => x.AddTeamAsync(It.IsAny <Team>())).ThrowsAsync(new DataException()); var controller = new TeamsController(_service.Object, _mapper, _logger.Object); var result = await controller.Add(MockedTeam()); Assert.IsNotNull(result); Assert.IsInstanceOf <IActionResult>(result); Assert.IsInstanceOf <ObjectResult>(result); Assert.AreEqual(StatusCodes.Status500InternalServerError, ((ObjectResult)result).StatusCode); Assert.IsNotNull(((ObjectResult)result).Value); Assert.IsNotEmpty(((ObjectResult)result).Value.ToString()); _service.Verify(x => x.AddTeamAsync(It.IsAny <Team>()), Times.Once); _logger.Verify(x => x.Log(LogLevel.Debug, It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Never); _logger.Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Once); }