Esempio n. 1
0
        public async Task Test_If_The_Product_Is_Added_To_The_Db()
        {
            //Setup
            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("ProdBasket");
            var appdbcon      = new ApplicationDbContext(optionBuilder.Options);

            //Arrange
            var product = new Product()
            {
                Id = 2, ProdName = "Abc", ProdImageName = "Abc.jpg", ProdPrice = 250
            };
            var prodRepo = new Repository <Product>(appdbcon);



            //Act
            prodRepo.Add(product);

            //Assert
            var result = await appdbcon.Products.FirstOrDefaultAsync();

            Assert.AreEqual(result.ProdName, product.ProdName);

            Assert.AreSame(product, result);
        }
        public void TestReferenceUpdate()
        {
            var so1 = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var so2 = new SimpleObject {
                ValueOne = 3, ValueTwo = 4
            };
            var ro = new ReferenceObject {
                ReferenceOne = so1
            };

            var clone = (ReferenceObject)CopyUtils.CloneObjectTest(ro);

            clone.ReferenceOne = so2;

            Assert.AreNotSame(ro, clone);
            Assert.AreSame(ro.GetType(), clone.GetType());
            Assert.AreNotSame(ro.ReferenceOne, clone.ReferenceOne);

            CopyUtils.UpdateFromClone(ro, clone);

            Assert.AreNotSame(ro, clone);
            Assert.AreSame(ro.GetType(), clone.GetType());
            Assert.AreSame(ro.ReferenceOne, clone.ReferenceOne);
        }
        public void CanGetFilesSpecifiedByIndex()
        {
            readWrite["Foo"] = null;
            readWrite["Bar"] = file;

            Assert.AreSame(readOnly[1], file);
        }
Esempio n. 4
0
        public void GetObjectFromId()
        {
            Claim  claim1 = NakedObjectsFramework.Persistor.Instances <Claim>().First();
            object claim2 = NakedObjectsFramework.GetObjectFromId(objectId);

            Assert.AreSame(claim1, claim2);
        }
Esempio n. 5
0
        public void GetCollectionNakedObjectFromId()
        {
            IList <Claim>       claims = NakedObjectsFramework.GetService <ClaimRepository>().FindMyClaims(null, "");
            INakedObjectAdapter no     = NakedObjectsFramework.NakedObjectManager.CreateAdapter(claims, null, null);

            INakedObjectAdapter service = NakedObjectsFramework.ServicesManager.GetService("ClaimRepository");
            IActionSpec         action  = service.Spec.GetActions().Single(a => a.Id == "FindMyClaims");

            INakedObjectAdapter[] parms = new[] { null, "" }.Select(o => NakedObjectsFramework.NakedObjectManager.CreateAdapter(o, null, null)).ToArray();

            var cm    = CollectionMementoHelper.TestMemento(NakedObjectsFramework.LifecycleManager, NakedObjectsFramework.NakedObjectManager, NakedObjectsFramework.MetamodelManager, service, action, parms);

            no.SetATransientOid(cm);

            string id = NakedObjectsFramework.GetObjectId(no);

            INakedObjectAdapter no2 = NakedObjectsFramework.GetNakedObjectFromId(id);

            List <Claim> claims2 = no2.GetDomainObject <IEnumerable <Claim> >().ToList();

            Assert.AreEqual(claims.Count(), claims2.Count());

            int index = 0;
            Dictionary <Claim, Claim> dict = claims.ToDictionary(x => x, y => claims2.Skip(index++).First());

            dict.ForEach(kvp => Assert.AreSame(kvp.Key, kvp.Value));
        }
        public void TestCollectionUpdate()
        {
            var so1 = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var so2 = new SimpleObject {
                ValueOne = 3, ValueTwo = 4
            };
            var co = new CollectionObject();

            co.CollectionOne.Add(so1);

            var clone = (CollectionObject)CopyUtils.CloneObjectTest(co);

            clone.CollectionOne.Add(so2);

            Assert.AreNotSame(co, clone);
            Assert.AreSame(co.GetType(), clone.GetType());
            Assert.AreNotSame(co.CollectionOne, clone.CollectionOne);
            Assert.AreNotEqual(co.CollectionOne.Count(), clone.CollectionOne.Count());

            CopyUtils.UpdateFromClone(co, clone);

            Assert.AreNotSame(co, clone);
            Assert.AreSame(co.GetType(), clone.GetType());
            Assert.AreNotSame(co.CollectionOne, clone.CollectionOne);
            Assert.AreEqual(co.CollectionOne.Count(), clone.CollectionOne.Count());
            Assert.AreSame(co.CollectionOne.First(), clone.CollectionOne.First());
            Assert.AreSame(co.CollectionOne.ElementAt(1), clone.CollectionOne.ElementAt(1));
        }
Esempio n. 7
0
 public void ReturnsValuesOfInParameters()
 {
     Assert.IsTrue(list.IsValueSet(IN_PARAMETER_INDEX), "in parameter should be set");
     Assert.AreSame(inValue, list[IN_PARAMETER_INDEX], "in value");
     Assert.IsTrue(list.IsValueSet(REF_PARAMETER_INDEX), "ref parameter should be set");
     Assert.AreSame(refValue, list[REF_PARAMETER_INDEX], "ref value");
 }
Esempio n. 8
0
        //Two different variables that reference the same object
        public void TwoVarsCanReferenceSameObject()
        {
            var book1 = GetBook("BOOK 1");
            var book2 = book1;

            Assert.AreSame(book1, book2);
            Assert.True(Object.ReferenceEquals(book1, book2));
        }
Esempio n. 9
0
        public void StoresResultToReturn()
        {
            invocation.Result = result;

            Assert.AreSame(result, invocation.Result, "should store result");
            Assert.IsFalse(invocation.IsThrowing, "should not be throwing");
            Assert.IsNull(invocation.Exception, "should not store an exception");
        }
Esempio n. 10
0
        public void StoresExceptionToThrow()
        {
            invocation.Exception = exception;

            Assert.AreSame(exception, invocation.Exception, "should store exception");
            Assert.IsTrue(invocation.IsThrowing, "should be throwing");
            Assert.IsNull(invocation.Result, "should not store a result");
        }
        public void AddTransientToSession()
        {
            HttpSessionStateBase session = mocks.HtmlHelper.ViewContext.HttpContext.Session;
            var claim = NakedObjectsFramework.LifecycleManager.CreateInstance((IObjectSpec)NakedObjectsFramework.MetamodelManager.GetSpecification(typeof(Claim))).GetDomainObject <Claim>();

            session.AddObjectToSession(Surface, "key1", claim);
            Assert.AreSame(claim, session.GetObjectFromSession <Claim>(Surface, "key1"));
        }
        public void AddPersistentToSession()
        {
            HttpSessionStateBase session = mocks.HtmlHelper.ViewContext.HttpContext.Session;
            Claim claim = NakedObjectsFramework.Persistor.Instances <Claim>().First();

            session.AddObjectToSession(Surface, "key1", claim);
            Assert.AreSame(claim, session.GetObjectFromSession <Claim>(Surface, "key1"));
        }
Esempio n. 13
0
        public void SettingResultClearsException()
        {
            invocation.Exception = exception;
            invocation.Result    = result;

            Assert.AreSame(result, invocation.Result, "should store result");
            Assert.IsFalse(invocation.IsThrowing, "should not be throwing");
            Assert.IsNull(invocation.Exception, "should not store an exception");
        }
Esempio n. 14
0
        public void GetNakedObjectFromId()
        {
            Claim claim1 = NakedObjectsFramework.Persistor.Instances <Claim>().First();
            var   id     = NakedObjectsFramework.GetObjectId(claim1);

            INakedObjectAdapter claim2 = NakedObjectsFramework.GetNakedObjectFromId(objectId);

            Assert.AreSame(claim1, claim2.Object);
        }
Esempio n. 15
0
        [Test] // fix later
        public void GetGenericObjectFromId()
        {
            var repo1 = GetTestService("Custom Helper Test Classes").NakedObject.Object;
            var id    = NakedObjectsFramework.GetObjectId(repo1);

            object repo2 = NakedObjectsFramework.GetObjectFromId(id);

            Assert.AreSame(repo1, repo2);
        }
Esempio n. 16
0
        public void MockObjectsMayBePlacedIntoServiceContainers()
        {
            var container  = new ServiceContainer();
            var mockedType = Mocks.CreateMock <IMockedType>();

            container.AddService(typeof(IMockedType), mockedType.MockObject);

            Assert.AreSame(mockedType.MockObject, container.GetService(typeof(IMockedType)));
        }
        public void AddStudent_ShouldAddStudentToListOfStudent()
        {
            var expectedId    = 10;
            var mockedStudent = new Mock <IStudent>();

            SchoolSystemEngine.AddStudent(expectedId, mockedStudent.Object);

            Assert.AreSame(SchoolSystemEngine.Students[expectedId], mockedStudent.Object);
        }
        public void AddTeacher_ShouldAddTeacherToListOfTeachers()
        {
            var expectedId    = 10;
            var mockedTeacher = new Mock <ITeacher>();

            SchoolSystemEngine.AddTeacher(expectedId, mockedTeacher.Object);

            Assert.AreSame(SchoolSystemEngine.Teachers[expectedId], mockedTeacher.Object);
        }
Esempio n. 19
0
        public void SettingExceptionClearsResult()
        {
            invocation.Result    = result;
            invocation.Exception = exception;

            Assert.AreSame(exception, invocation.Exception, "should store exception");
            Assert.IsTrue(invocation.IsThrowing, "should be throwing");
            Assert.IsNull(invocation.Result, "should not store a result");
        }
        public void RemoveObjectFromCache()
        {
            HttpSessionStateBase session = mocks.HtmlHelper.ViewContext.HttpContext.Session;
            Claim claim = NakedObjectsFramework.Persistor.Instances <Claim>().First();

            session.AddObjectToSession(NakedObjectsFramework, "key1", claim);
            Assert.AreSame(claim, session.GetObjectFromSession <Claim>(NakedObjectsFramework, "key1"));
            session.ClearFromSession("key1");
            Assert.IsNull(session.GetObjectFromSession <Claim>(NakedObjectsFramework, "key1"));
        }
Esempio n. 21
0
        public void Can_View_Cart_Contents()
        {
            var comparison = new Comparison();

            sutController = new ComparingController(null);
            var result = (ComparisonIndexViewModel)sutController.Index(comparison, "myUrl").ViewData.Model;

            Assert.AreSame(result.CompareCollection, comparison);
            Assert.AreEqual(result.ReturnUrl, "myUrl");
        }
Esempio n. 22
0
        public void SetAndGetProperty()
        {
            object value = "hello";

            DependencyProvider.MockObject.GetAndSetProperty = value;
            Assert.AreSame(value, DependencyProvider.MockObject.GetAndSetProperty);

            DependencyProvider.MockObject.GetAndSetProperty = 3;
            Assert.AreEqual(3, DependencyProvider.MockObject.GetAndSetProperty, "wrong value on second set.");
        }
Esempio n. 23
0
        public void CanSpecifyFiles()
        {
            var mocks = new MockRepository();
            var file  = mocks.DynamicMock <HttpPostedFileBase>();

            builder.Files["Variable"] = file;
            var controller = new TestHelperController();

            builder.InitializeController(controller);
            Assert.AreSame(file, controller.Request.Files["Variable"]);
        }
Esempio n. 24
0
        public void UserShouldBeMocked()
        {
            var mocks = new MockRepository();
            var user  = mocks.DynamicMock <IPrincipal>();

            var controller = builder.CreateController <TestHelperController>();

            controller.ControllerContext.HttpContext.User = user;

            Assert.AreSame(user, controller.User);
        }
Esempio n. 25
0
        public void CanSetValuesOfOutAndRefParameters()
        {
            object newRefValue = "newRefValue";
            object outValue    = "outValue";

            list[REF_PARAMETER_INDEX] = newRefValue;
            list[OUT_PARAMETER_INDEX] = outValue;

            Assert.AreSame(newRefValue, list[REF_PARAMETER_INDEX], "new ref value");
            Assert.IsTrue(list.IsValueSet(OUT_PARAMETER_INDEX), "out parameter is set");
            Assert.AreSame(outValue, list[OUT_PARAMETER_INDEX], "out value");
        }
        public void TestSimpleClone()
        {
            var so = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var clone = (SimpleObject)CopyUtils.CloneObjectTest(so);

            Assert.AreNotSame(so, clone);
            Assert.AreSame(so.GetType(), clone.GetType());
            Assert.AreEqual(so.ValueOne, clone.ValueOne);
            Assert.AreEqual(so.ValueTwo, clone.ValueTwo);
        }
Esempio n. 27
0
        public void TestBuildEntityMixed(uint id)
        {
            TestIt testIt = new TestIt(2);

            _entityFactory.BuildEntity <TestEntityWithComponentViewAndComponent>(new EGID(id, group1), new[] { testIt });
            _simpleSubmissionEntityViewScheduler.SubmitEntities();

            Assert.IsTrue(_neverDoThisIsJustForTheTest.HasEntity <TestEntityViewComponent>(new EGID(id, group1)));
            Assert.IsTrue(_neverDoThisIsJustForTheTest.HasAnyEntityInGroup <TestEntityComponent>(group1));
            Assert.IsTrue(_neverDoThisIsJustForTheTest.HasAnyEntityInGroup <TestEntityViewComponent>(group1));
            var(entityCollection, count) =
                _neverDoThisIsJustForTheTest.entitiesDB.QueryEntities <TestEntityViewComponent>(group1);
            Assert.AreSame(entityCollection[0].TestIt, testIt);
        }
Esempio n. 28
0
        public void GetAllSpecializationsTest()
        {
            //Arrange
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(a => a.Specializations.GetAll()).Returns(It.IsAny <List <Specialization> >);

            //Act
            var service = new SpecializationService(mock.Object);

            var list = new List <SpecializationDto>();

            Assert.AreSame(list.GetType(), service.GetSpecializations().GetType());
        }
        public void TestCollectionClone()
        {
            var so = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var co = new CollectionObject();

            co.CollectionOne.Add(so);

            var clone = (CollectionObject)CopyUtils.CloneObjectTest(co);

            Assert.AreNotSame(co, clone);
            Assert.AreSame(co.GetType(), clone.GetType());
            Assert.AreNotSame(co.CollectionOne, clone.CollectionOne);
            Assert.AreSame(co.CollectionOne.First(), clone.CollectionOne.First());
        }
Esempio n. 30
0
        public void TrapsExceptionsWhenInvokedOnAnotherObject()
        {
            Exception exception = new Exception("thrown from Foo");

            invocation = new Invocation(receiver, FOO_METHOD, new object[] { "input", null });

            MockFoo mockFoo = new MockFoo();

            mockFoo.Foo_ExpectedInput = "input";
            mockFoo.Foo_Exception     = exception;

            invocation.InvokeOn(mockFoo);

            Assert.IsTrue(mockFoo.FooWasInvoked, "Foo should have been invoked");
            Assert.AreSame(exception, invocation.Exception, "exception");
        }