static StylesMockRepository() { IMockUnitOfWork muw = new MockUnitOfWork(); IEntityRepository <MockRule> ruleStore = muw.Repository <MockRule>(); List <RuleDTO> rules = StylesDataInitializer.GetRules(); foreach (var item in rules) { ruleStore.Insert(new MockRule { Selector = item.Selector, Name = item.Name, Category = item.Category, Scope = item.Scope, DefaultStyle = new MockStyle() { Color = item.Style.Color, BackgroundColor = item.Style.BackgroundColor, BackgroundImage = item.Style.BackgroundImage } }); } muw.SaveChanges(); }
public void IocUnitOfWorkMockedTest() { //EXAMPLE: Shows how to set up a Mocked Repository //Set up facked repository var mockedUnitOfWork = new MockUnitOfWork(); mockedUnitOfWork.Repository<Tuple<int, string>>().Add(new Tuple<int, string>(1, "First")); mockedUnitOfWork.Repository<Tuple<int, string>>().Add(new Tuple<int, string>(2, string.Empty)); mockedUnitOfWork.Repository<Tuple<int, string>>().Add(new Tuple<int, string>(3, "Third")); //Call into IoC for IUnitOfWork and validate items came back. using (IoC ioc = new IoC(modules: new MockUnitOfWorkModule(mockedUnitOfWork))) using (var unitOfWork = ioc.Resolve<IUnitOfWork>()) { var repository = unitOfWork.Repository<Tuple<int, string>>(); var items = repository .Queryable .Where(i => !string.IsNullOrEmpty(i.Item2)) .ToList(); Assert.IsTrue(items.Any()); } }