public async Task TestAutoCodeGenerate() { //Context has been overriding and an in-memory autocode data has been added. var mockAutoCodeSet = IMUow.Repository <AutoCode>().GetListAsync(AutoCodeDtos.InMemoryList()); mockContext.Setup(m => m.Set <AutoCode>()).Returns(mockAutoCodeSet.Object); //Context has been overriding and add mocked AutoCodeLog DbSet. var mockAutoCodeLogSet = new Mock <DbSet <AutoCodeLog> >(); mockContext.Setup(m => m.Set <AutoCodeLog>()).Returns(mockAutoCodeLogSet.Object); //Unit of work has been mocked. Mock context sent to constructor. Services works with mocked unit of work. var mockUow = new Mock <EntityUnitofWork <Guid> >(mockContext.Object); _autoCodeLogService = new AutoCodeLogService(mockUow.Object); _autoCodeService = new AutoCodeService(mockUow.Object, _autoCodeLogService); var result = await _autoCodeService.AutoCodeGenerate( AutoCodeDtos.ScreenCodeForAutomaticCodeGenerationTest, UserDtos.InMemoryList().First().ID); //Is the expected code the same as the generated code? Assert.AreEqual("CF-143-UT", result); //Has the last code number increased? Assert.AreEqual( 143, mockAutoCodeSet.Object. FirstOrDefault(x => x.ScreenCode == AutoCodeDtos.ScreenCodeForAutomaticCodeGenerationTest).LastCodeNumber); mockAutoCodeLogSet.Verify(m => m.Add(It.IsAny <AutoCodeLog>()), Times.Once); mockUow.Verify(m => m.SaveChangesAsync(), Times.Once); }
public void TestCheckScreenCode() { var mockUow = new Mock <EntityUnitofWork <Guid> >(mockContext.Object); _autoCodeLogService = new AutoCodeLogService(mockUow.Object); AutoCodeService _autoCodeService = new AutoCodeService(mockUow.Object, _autoCodeLogService); var incorrectScreenCode = _autoCodeService.CheckScreenCode(AutoCodeDtos.IncorrectScreenCode); var correctScrennCode = _autoCodeService.CheckScreenCode(ScreenCodes.TSC01); Assert.IsFalse(incorrectScreenCode); Assert.IsTrue(correctScrennCode); }
public void TestCheckCodeFormat() { var mockUow = new Mock <EntityUnitofWork <Guid> >(mockContext.Object); _autoCodeLogService = new AutoCodeLogService(mockUow.Object); AutoCodeService _autoCodeService = new AutoCodeService(mockUow.Object, _autoCodeLogService); var incorrectCodeFormat = _autoCodeService.CheckCodeFormat(AutoCodeDtos.IncorrectCodeFormat); var correctCodeFormat = _autoCodeService.CheckCodeFormat(AutoCodeDtos.CorrectCodeFormat); Assert.IsFalse(incorrectCodeFormat); Assert.IsTrue(correctCodeFormat); }
public AutoCodeController(IAutoCodeService service, IdentityClaimsValue identityClaimsValue, IAutoCodeLogService autoCodeLogService) : base(service, identityClaimsValue) { _autoCodeLogService = autoCodeLogService; }
public AutoCodeController(IAutoCodeService service, IAutoCodeLogService autoCodeLogService) : base(service) { _autoCodeLogService = autoCodeLogService; }
public AutoCodeService(UnitOfWork <Guid> uow, IMapper mapper, IAutoCodeLogService autoCodeLogService) : base(uow, mapper) { _autoCodeLogService = autoCodeLogService; }
public AutoCodeService(EntityUnitofWork <Guid> uow, IAutoCodeLogService autoCodeLogService) : base(uow) { _autoCodeLogService = autoCodeLogService; }
public AutoCodeService(EntityUnitofWork <Guid> _uow, IAutoCodeLogService _autoCodeLogService) : base(_uow) { autoCodeLogService = _autoCodeLogService; }
public AutoCodeController(IAutoCodeService _service, IAutoCodeLogService _autoCodeLogService) : base(_service) { autoCodeLogService = _autoCodeLogService; }