public void Map_toDomain_Test() { //Arange var dummyRoleMapper = new RoleMapper(); var dummyUserMapper = new UserMapper(dummyRoleMapper); var dummyOptionMapper = new OptionsMapper(); var dummySectionMapper = new SectionMapper(); IScriptMapper mapper = new ScriptMapper(dummyUserMapper, dummyOptionMapper, dummySectionMapper, new CookieParser()); var script = new TransferScript { EntityState = EntityState.Unchanged, OperatorId = 99, ScriptId = 99, Title = "test", CreatedDate = new DateTime(1, 1, 1), LastEditedDate = new DateTime(1, 1, 1), OptionsId = 99, PrompterId = 99, Options = null, Operator = null, Prompter = null }; var expected = new ComparableScript { EntityState = EntityState.Unchanged, OperatorId = 99, ScriptId = 99, Title = "test", CreatedDate = new DateTime(1, 1, 1), LastEditedDate = new DateTime(1, 1, 1), OptionsId = 99, PrompterId = 99, Options = null, Operator = null, Prompter = null }; //Act var actual = mapper.Map(script); //Assert Assert.That(actual, Is.EqualTo(expected)); Assert.That(actual.Options, Is.Null); Assert.That(actual.Operator, Is.Null); Assert.That(actual.Prompter, Is.Null); }
public Script Map(TransferScript transferScript) { if (transferScript == null) { return(null); } Script script = new Script { ScriptId = transferScript.ScriptId, Title = transferScript.Title, CreatedDate = transferScript.CreatedDate, Description = transferScript.Description, LastEditedDate = transferScript.LastEditedDate, OperatorId = transferScript.OperatorId, PrompterId = transferScript.PrompterId, OptionsId = transferScript.OptionsId, Options = _optionsMapper.Map(transferScript.Options), EntityState = transferScript.EntityState }; if (script.EntityState == EntityState.Added) { var identity = (FormsIdentity)HttpContext.Current.User.Identity; script.OperatorId = _cookieParser.GetUserId(identity); } if (transferScript.Sections != null) { script.Sections = transferScript.Sections .Select(section => _sectionMapper.Map(section)) .ToList(); } return(script); }
public TransferScript Map(Script script) { if (script == null) { return(null); } TransferScript transferScript = new TransferScript { ScriptId = script.ScriptId, Title = script.Title, CreatedDate = script.CreatedDate, Description = script.Description, LastEditedDate = script.LastEditedDate, OperatorId = script.OperatorId, PrompterId = script.PrompterId, OptionsId = script.OptionsId, Operator = _userMapper.Map(script.Operator), Prompter = _userMapper.Map(script.Prompter), Options = _optionsMapper.Map(script.Options), EntityState = EntityState.Unchanged }; if (script.Sections != null) { transferScript.Sections = script.Sections .Select(section => _sectionMapper.Map(section)) .ToList(); } return(transferScript); }
public void Get_ById_Test() { //Arange var stubScriptService = new Mock <IScriptService>(); var stubMapper = new Mock <IScriptMapper>(); var script = new Script { ScriptId = 1 }; var transferScript = new TransferScript { ScriptId = 1 }; stubScriptService.Setup(ss => ss.FetchScriptById(1)) .Returns(script); stubMapper.Setup(m => m.Map(script)) .Returns(transferScript); var controller = new ScriptController(stubScriptService.Object, stubMapper.Object, new CookieParser()); //Act var actual = controller.Get(1); //Assert Assert.That(actual.ScriptId == script.ScriptId); stubMapper.Verify(m => m.Map(script), Times.Once); stubScriptService.Verify(ss => ss.FetchScriptById(1), Times.Once); }