public void AddManager(IFake <BaseItem> newManager, string managerID) { if (!IsManagerExist(managerID)) { managerDictionary.Add(managerID, newManager); } }
public void StergereCategorie(IFake context, int categorieId) { Categorii categorie = context.Categorii.FirstOrDefault(a => a.Id == categorieId); context.Categorii.Remove(categorie); context.SaveChanges(); }
private void AddToRepository(IList <IFake> fakeList, IFake parent) { CreateMockFor <IContent>(parent, fakeList); CreateMockFor <IContentData>(parent, fakeList); CreateMockFor <ContentData>(parent, fakeList); var parentDescendants = GetDescendantsOf(parent, new List <IContent>()); _contentRepo .Setup(repo => repo.GetDescendents(parent.Content.ContentLink)) .Returns(parentDescendants); _contentLoader .Setup(repo => repo.GetDescendents(parent.Content.ContentLink)) .Returns(parentDescendants); foreach (var fake in fakeList) { var item = fake; CreateMockFor <IContent>(fake); CreateMockFor <IContentData>(fake); CreateMockFor <ContentData>(fake); (fake as Fake).HelpCreatingMockForCurrentType(this); var pageDescendants = GetDescendantsOf(item, new List <IContent>()); _contentRepo .Setup(repo => repo.GetDescendents(item.Content.ContentLink)) .Returns(pageDescendants); AddToRepository(item.Children, item); } }
public virtual FakePage ChildOf(IFake parent) { parent.Children.Add(this); Content.Property["PageParentLink"] = new PropertyPageReference(parent.Content.ContentLink); return(this); }
public TakeArguments(IFake fake, Int val, string match, int testint = 0, int testb = 1) { FakeValue = fake.Value; IntValue = val.Value; Match = match; TestInt = testint; TestB = testb; }
public void StergereArticol(IFake context, int articolID) { Articol art = context.Articol.FirstOrDefault(a => a.Id == articolID); context.Articol.Remove(art); context.SaveChanges(); }
public virtual FakeProduct ChildOf(IFake parent) { parent.Children.Add(this); Product.ParentLink = parent.Content.ContentLink; return(this); }
public void AddToRepository(IFake fake) { CreateMockFor <IContent>(fake); CreateMockFor <IContentData>(fake); CreateMockFor <ContentData>(fake); (fake as Fake).HelpCreatingMockForCurrentType(this); AddToRepository(fake.Children, fake); }
public void CreateMockFor <T>(IFake item) where T : class, IContentData { _contentRepo .Setup(repo => repo.Get <T>(item.Content.ContentLink)) .Returns(item.Content as T); _contentLoader .Setup(repo => repo.Get <T>(item.Content.ContentLink)) .Returns(item.Content as T); }
public void EditareArticol(IFake context, string titluOld, Articol updatedArticol) { Articol articol = context.Articol.FirstOrDefault(a => a.Titlu.Contains(titluOld)); articol.Titlu = updatedArticol.Titlu; articol.Continut = updatedArticol.Continut; articol.Descriere = updatedArticol.Descriere; articol.Categorie = updatedArticol.Categorie; articol.Link = updatedArticol.Link; context.SaveChanges(); }
private static IEnumerable <ContentReference> GetDescendantsOf(IFake fake, ICollection <IContent> descendants) { foreach (var child in fake.Children) { descendants.Add(child.Content); GetDescendantsOf(child, descendants); } return(descendants.Select(descendant => descendant.ContentLink).ToList()); }
public void RegisteredFuncReturnNullTest() { //Arrange ServiceLocator.Register <FakeOne>(() => { return(null); }); //Act IFake impl1 = ServiceLocator.Resolve <FakeOne>(); //Assert Assert.IsNull(impl1); }
public void CreateMockFor <T>(IFake parent, IList <IFake> fakeList) where T : class, IContentData { var contentList = fakeList.Select(fake => fake.Content as T).ToList(); _contentRepo .Setup(repo => repo.GetChildren <T>(parent.Content.ContentLink)) .Returns(contentList); _contentLoader .Setup(repo => repo.GetChildren <T>(parent.Content.ContentLink)) .Returns(contentList); }
public void RegisterAndResolveTest() { //Arrange ServiceLocator.Register(() => new FakeOne()); //Act IFake impl1 = ServiceLocator.Resolve <FakeOne>(); //Assert Assert.IsNotNull(impl1); Assert.IsTrue(impl1 is FakeOne); }
public int AdaugareCategorie(IFake context, string categorie) { int ID_Categorie; Categorii cat = new Categorii() { Nume = categorie }; context.Categorii.Add(cat); context.SaveChanges(); ID_Categorie = cat.Id; return(ID_Categorie); }
public static object Create(Type clientType, IFake fake) { if (!Dictionary.TryGetValue(clientType, out ProxyBuilder builder)) { lock (Syncs.GetOrAdd(clientType, k => new object())) { if (!Dictionary.TryGetValue(clientType, out builder)) { builder = new ProxyBuilder(clientType); Dictionary.Add(clientType, builder); } } } return(builder.Build(fake)); }
public void RegisterTwoDifferentImplementationTest() { //Arrange bool first = ServiceLocator.Register <IFake>(() => new FakeOne()); bool second = ServiceLocator.Register <IFake>(() => new FakeTwo()); //Act IFake impl1 = ServiceLocator.Resolve <IFake>(); IFake impl2 = ServiceLocator.Resolve <IFake>(); //Assert Assert.IsTrue(first); Assert.IsFalse(second); Assert.IsNotNull(impl1); Assert.IsNotNull(impl2); Assert.IsTrue(impl1 is FakeOne); Assert.IsTrue(impl2 is FakeOne); }
public void RegisterTheSameTypeTwiceFailTest() { //Arrange bool first = ServiceLocator.Register <FakeOne>(() => new FakeOne("first")); bool second = ServiceLocator.Register <FakeOne>(() => new FakeOne("second")); //Act IFake impl1 = ServiceLocator.Resolve <FakeOne>(); IFake impl2 = ServiceLocator.Resolve <FakeOne>(); //Assert Assert.IsTrue(first); Assert.IsFalse(second); Assert.IsNotNull(impl1); Assert.IsNotNull(impl2); Assert.IsTrue(impl1 is FakeOne); Assert.IsTrue(impl2 is FakeOne); Assert.AreEqual("first", impl1.GetSomething()); Assert.AreEqual("first", impl2.GetSomething()); }
public int AdaugareArticol(IFake context, int ID_Categorie, string titlu, string continut, string descriere, string link, DateTime dataPublicare, User user) { if (user == null) { return(-1); } Articol art = new Articol() { Titlu = titlu, Continut = continut, Descriere = descriere, Categorie = ID_Categorie, Link = link, User = user, Data_Publicare = dataPublicare }; context.Articol.Add(art); context.SaveChanges(); int IDUL = art.Id; return(IDUL); }
public FakeSelector(IFake internalFake) { Contract.Requires(internalFake != null); _internalFake = internalFake; }
public object Build(IFake fake) { var weak = new WeakReference(_creator.Value(fake), false); return(weak.Target); }
public void CreateObjectsTest() { IServiceCollection pool = Implementation.CreateServiceCollection(); IServiceScopeFactory factory = Implementation.CreateServiceScopeFactory(pool); IServiceProvider services = factory.CreateScope().ServiceProvider; try { object staticobj = services.CreateInstance(typeof(StaticObject), 10) as StaticObject; Assert.Fail(); } catch (InvalidOperationException) { } try { IFake fakeobj = services.CreateInstance <IFake>(); Assert.Fail(); } catch (InvalidOperationException) { } try { AbstractObject absobj = services.CreateInstance <AbstractObject>(); Assert.Fail(); } catch (InvalidOperationException) { } try { PrivateObject privateobj = services.CreateInstance <PrivateObject>(5); Assert.Fail(); } catch (InvalidOperationException) { } try { EnumTest enumobj = services.CreateInstance <EnumTest>(); Assert.Fail(); } catch (InvalidOperationException) { } try { DelegateTest delegateobj = services.CreateInstance <DelegateTest>(); Assert.Fail(); } catch (Exception) { } GenericObject <int> intgeneric = services.CreateInstance <GenericObject <int> >(10); Assert.AreEqual(10, intgeneric.Value); GenericObject <double> doublegeneric = services.CreateInstance <GenericObject <double> >(); Assert.AreEqual(0, doublegeneric.Value); try { int[] intarray = services.CreateInstance <int[]>(10); Assert.Fail(); } catch (InvalidOperationException) { } int inttest = services.CreateInstance <int>(5); Assert.AreEqual(5, inttest); StructObject structobj = services.CreateInstance <StructObject>(5); Assert.AreEqual(5, structobj.Value); }
public void Init() { this.fake = A.Fake <IFake>(); }
public void CreateMockFor(IFake fake, Expression <Func <IContentLoader, IContent> > expression) { _contentLoader .Setup(expression) .Returns(fake.Content); }
public void CreateMockFor(IFake fake, Expression <Func <IContentRepository, IContent> > expression) { _contentRepo .Setup(expression) .Returns(fake.Content); }
public void Init() { this.fake = A.Fake <IFake>(); A.CallTo(() => fake.IntReturnWith0Parameters()).Returns(1); }
protected void RegisterFake <TService>(IFake <TService> fake) where TService : class { IntegrationTestsHelper <TFakeFactory> .RegisterFake(GetIocContainer(), fake); }
/// <summary> /// Registers service fake into the scenario context. /// </summary> /// <typeparam name="TService">The type of service.</typeparam> /// <param name="fake">The fake to be registered.</param> protected void RegisterFake <TService>(IFake <TService> fake) where TService : class { RegistrationHelper.RegisterFake(GetRegistrator(), fake); }