Esempio n. 1
0
 public void AddManager(IFake <BaseItem> newManager, string managerID)
 {
     if (!IsManagerExist(managerID))
     {
         managerDictionary.Add(managerID, newManager);
     }
 }
Esempio n. 2
0
        public void StergereCategorie(IFake context, int categorieId)
        {
            Categorii categorie = context.Categorii.FirstOrDefault(a => a.Id == categorieId);

            context.Categorii.Remove(categorie);
            context.SaveChanges();
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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;
 }
Esempio n. 6
0
        public void StergereArticol(IFake context, int articolID)
        {
            Articol art = context.Articol.FirstOrDefault(a => a.Id == articolID);

            context.Articol.Remove(art);

            context.SaveChanges();
        }
Esempio n. 7
0
        public virtual FakeProduct ChildOf(IFake parent)
        {
            parent.Children.Add(this);

            Product.ParentLink = parent.Content.ContentLink;

            return(this);
        }
Esempio n. 8
0
        public void AddToRepository(IFake fake)
        {
            CreateMockFor <IContent>(fake);
            CreateMockFor <IContentData>(fake);
            CreateMockFor <ContentData>(fake);

            (fake as Fake).HelpCreatingMockForCurrentType(this);

            AddToRepository(fake.Children, fake);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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();
        }
Esempio n. 11
0
        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());
        }
Esempio n. 12
0
        public void RegisteredFuncReturnNullTest()
        {
            //Arrange
            ServiceLocator.Register <FakeOne>(() => { return(null); });

            //Act
            IFake impl1 = ServiceLocator.Resolve <FakeOne>();

            //Assert
            Assert.IsNull(impl1);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        public void RegisterAndResolveTest()
        {
            //Arrange
            ServiceLocator.Register(() => new FakeOne());

            //Act
            IFake impl1 = ServiceLocator.Resolve <FakeOne>();

            //Assert
            Assert.IsNotNull(impl1);
            Assert.IsTrue(impl1 is FakeOne);
        }
Esempio n. 15
0
        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));
 }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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());
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
 public FakeSelector(IFake internalFake)
 {
     Contract.Requires(internalFake != null);
     _internalFake = internalFake;
 }
Esempio n. 21
0
 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);
        }
Esempio n. 24
0
 public void Init()
 {
     this.fake = A.Fake <IFake>();
 }
Esempio n. 25
0
 public void CreateMockFor(IFake fake, Expression <Func <IContentLoader, IContent> > expression)
 {
     _contentLoader
     .Setup(expression)
     .Returns(fake.Content);
 }
Esempio n. 26
0
 public void CreateMockFor(IFake fake, Expression <Func <IContentRepository, IContent> > expression)
 {
     _contentRepo
     .Setup(expression)
     .Returns(fake.Content);
 }
Esempio n. 27
0
 public void Init()
 {
     this.fake = A.Fake <IFake>();
     A.CallTo(() => fake.IntReturnWith0Parameters()).Returns(1);
 }
Esempio n. 28
0
 protected void RegisterFake <TService>(IFake <TService> fake) where TService : class
 {
     IntegrationTestsHelper <TFakeFactory> .RegisterFake(GetIocContainer(), fake);
 }
Esempio n. 29
0
 /// <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);
 }