Exemplo n.º 1
0
 public void AddManager(IFake <BaseItem> newManager, string managerID)
 {
     if (!IsManagerExist(managerID))
     {
         managerDictionary.Add(managerID, newManager);
     }
 }
Exemplo 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();
        }
Exemplo 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);
            }
        }
Exemplo 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;
 }
Exemplo 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();
        }
Exemplo n.º 7
0
        public virtual FakeProduct ChildOf(IFake parent)
        {
            parent.Children.Add(this);

            Product.ParentLink = parent.Content.ContentLink;

            return(this);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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();
        }
Exemplo 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());
        }
Exemplo n.º 12
0
        public void RegisteredFuncReturnNullTest()
        {
            //Arrange
            ServiceLocator.Register <FakeOne>(() => { return(null); });

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

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