Esempio n. 1
0
        public void GetVertexById(bool pFound)
        {
            const long id  = 13241235;
            var        app = (pFound ? new App() : null);

            vMockAcc = MockDataAccess.Create(mda => {
                MockDataAccessCmd cmd = mda.GetCommand(0);
                Assert.AreEqual(GetVertexByIdScript, cmd.Script, "Incorrect Query.Script.");
                TestUtil.CheckParams(cmd.Params, "_P", new List <object> {
                    id
                });
            });
            vMockAcc.MockResult.SetupToElement(app);
            vMockCache.Setup(x => x.FindVertex <App>(id)).Returns((App)null);
            vMockCache.Setup(x => x.AddVertex(app, null));
            vMockCache.Setup(x => x.RemoveVertex <App>(id)).Returns((App)null);
            vMockFact.Setup(x => x.Create(null, false, true)).Returns(vMockAcc.Object);

            App result = vData.GetVertexById <App>(id);

            Assert.AreEqual(app, result, "Incorrect result.");
            vMockCache.Verify(x => x.FindVertex <App>(id), Times.Once);

            if (pFound)
            {
                vMockCache.Verify(x => x.RemoveVertex <App>(id), Times.Never);
                vMockCache.Verify(x => x.AddVertex(app, null), Times.Once);
            }
            else
            {
                vMockCache.Verify(x => x.RemoveVertex <App>(id), Times.Once);
                vMockCache.Verify(x => x.AddVertex(app, null), Times.Never);
            }
        }
Esempio n. 2
0
        public void GetMemberByRefresh(int pResultCount)
        {
            const long   appId = 125125235;
            const string code  = "asdugalsdgualsdkgulsdkug";
            var          mem   = new Member();

            var mockDataAcc = MockDataAccess.Create(mda => {
                Assert.AreEqual(MockDataAccess.SessionStart, mda.GetCommand(0).SessionAction,
                                "Incorrect Command 0 SessionAction.");

                string expectScript = "m=g.V('" + DbName.Vert.OauthAccess.Refresh + "',_P)" +
                                      ".outE('" + DbName.Edge.OauthAccessAuthenticatesMemberName + "').inV;" +
                                      "(m?m=m.next():null);";
                var expectParam = new List <object> {
                    code
                };
                TestUtil.CheckWeaverScript(mda.GetCommand(1), expectScript, "_P", expectParam);

                expectScript = "m.outE('" + DbName.Edge.MemberDefinedByAppName + "')" +
                               ".inV.property('" + DbName.Vert.Vertex.VertexId + "');";
                expectParam = new List <object>();
                TestUtil.CheckWeaverScript(mda.GetCommand(2), expectScript, "_P", expectParam);

                Assert.AreEqual(MockDataAccess.SessionClose, mda.GetCommand(3).SessionAction,
                                "Incorrect Command 3 SessionAction.");

                Assert.AreEqual("OauthAccess-GetMemberByRefresh",
                                mda.Object.ExecuteName, "Incorrect ExecuteName.");
            });

            mockDataAcc.MockResult
            .Setup(x => x.GetCommandResultCount(pResultCount))
            .Returns(1);

            mockDataAcc.MockResult
            .Setup(x => x.ToElementAt <Member>(1, 0))
            .Returns(mem);

            mockDataAcc.MockResult
            .Setup(x => x.ToLongAt(2, 0))
            .Returns(appId);

            vMockData
            .Setup(x => x.Build(null, true, true))
            .Returns(mockDataAcc.Object);

            OauthMember result = vTasks.GetMemberByRefresh(vMockData.Object, code);

            if (pResultCount == 0)
            {
                Assert.Null(result, "Result should be null.");
                return;
            }

            Assert.NotNull(result, "Result should be filled.");
            Assert.AreEqual(mem, result.Member, "Incorrect Member.");
            Assert.AreEqual(appId, result.AppId, "Incorrect AppId.");
        }
Esempio n. 3
0
        public void SetOauthTokenDuplicate()
        {
            Member mem = new Member {
                MemberType = (byte)MemberType.Id.Admin
            };

            var mockAcc = MockDataAccess.Create(OnExecuteGetMember);

            mockAcc.MockResult.SetupToElement(mem);

            var oa = new OperationAuth(null, () => mockAcc.Object, () => vExpire);

            oa.SetOauthToken(vToken);
            TestUtil.Throws <Exception>(() => oa.SetOauthToken("duplicate"));
        }
Esempio n. 4
0
        public void SetOauthTokenAndExecuteOauth(MemberType.Id?pMemType, bool pSuccess)
        {
            const int expInSec = 99;
            Member    mem      = null;

            if (pMemType != null)
            {
                mem                   = new Member();
                mem.VertexId          = vMemId;
                mem.MemberType        = (byte)pMemType;
                mem.OauthGrantExpires = new DateTime(vExpire).AddSeconds(expInSec).Ticks;
            }

            var mockAcc = MockDataAccess.Create(OnExecuteGetMember);

            mockAcc.MockResult.SetupToElement(mem);

            var mockCache = new Mock <IMemCache>(MockBehavior.Strict);

            mockCache.Setup(x => x.FindOauthMember(vToken)).Returns((Member)null);
            mockCache.Setup(x => x.AddOauthMember(vToken, mem, expInSec));

            var oa = new OperationAuth(mockCache.Object, () => mockAcc.Object, () => vExpire);

            oa.SetOauthToken(vToken);

            TestUtil.CheckThrows <FabOauthFault>(!pSuccess, oa.ExecuteOauth);

            if (pSuccess)
            {
                Assert.AreEqual(mem.VertexId, oa.ActiveMemberId, "Incorrect ActiveMemberId.");
                mockCache.Verify(x => x.AddOauthMember(vToken, mem, expInSec), Times.Once);
            }
            else
            {
                Assert.Null(oa.ActiveMemberId, "ActiveMemberId should be null.");
            }
        }
Esempio n. 5
0
        public void SetUp()
        {
            vMockAcc = MockDataAccess.Create(mda => {
                MockDataAccessCmd cmd = mda.GetCommand(0);
                Assert.AreEqual(BasicScript + ";", cmd.Script, "Incorrect Query.Script.");
                TestUtil.CheckParams(cmd.Params, "_P", new List <object>());
            });

            vMockFact = new Mock <IDataAccessFactory>(MockBehavior.Strict);
            vMockFact.Setup(x => x.Create(null, false, true)).Returns(vMockAcc.Object);

            vMockMet = new Mock <IMetricsManager>(MockBehavior.Strict);
            vMockMet.Setup(x => x.Counter(It.IsAny <string>(), It.IsAny <long>()));
            vMockMet.Setup(x => x.Timer(It.IsAny <string>(), It.IsAny <long>()));
            vMockMet.Setup(x => x.Mean(It.IsAny <string>(), It.IsAny <long>()));

            vMockCache = new Mock <IMemCache>(MockBehavior.Strict);

            vData = new OperationData(new Guid(), vMockFact.Object, vMockMet.Object, vMockCache.Object);

            vBasicQuery = new WeaverQuery();
            vBasicQuery.FinalizeQuery(BasicScript);
        }
        public void Success()
        {
            const long userId = 1342653246;
            const long appId  = 4634634;

            var mockDataAcc = MockDataAccess.Create(mda => {
                Assert.AreEqual(MockDataAccess.SessionStart, mda.GetCommand(0).SessionAction,
                                "Incorrect Command 0 SessionAction.");

                string expectScript = "m=g.V('" + DbName.Vert.Vertex.VertexId + "',_P).next();";
                var expectParam     = new List <object> {
                    vMem.VertexId
                };
                TestUtil.CheckWeaverScript(mda.GetCommand(1), expectScript, "_P", expectParam);

                expectScript = "m.outE('" + DbName.Edge.MemberDefinedByUserName + "')" +
                               ".inV.property('" + DbName.Vert.Vertex.VertexId + "');";
                expectParam = new List <object>();
                TestUtil.CheckWeaverScript(mda.GetCommand(2), expectScript, "_P", expectParam);

                expectScript = "m.outE('" + DbName.Edge.MemberDefinedByAppName + "')" +
                               ".inV.property('" + DbName.Vert.Vertex.VertexId + "');";
                expectParam = new List <object>();
                TestUtil.CheckWeaverScript(mda.GetCommand(3), expectScript, "_P", expectParam);

                Assert.AreEqual(MockDataAccess.SessionClose, mda.GetCommand(4).SessionAction,
                                "Incorrect Command 4 SessionAction.");

                Assert.AreEqual("Web-GetMemberDetails",
                                mda.Object.ExecuteName, "Incorrect ExecuteName.");
            });

            mockDataAcc.MockResult
            .Setup(x => x.ToLongAt(2, 0))
            .Returns(userId);

            mockDataAcc.MockResult
            .Setup(x => x.ToLongAt(3, 0))
            .Returns(appId);

            vMockData
            .Setup(x => x.Build(null, false, true))
            .Returns(mockDataAcc.Object);

            ////

            const string expectUpdateScript =
                "g.V('" + DbName.Vert.Vertex.VertexId + "',_P)" +
                ".sideEffect{it.setProperty('" + DbName.Vert.Member.MemberType + "',_P);}" +
                ".outE('" + DbName.Edge.MemberDefinedByUserName + "').inV" +
                ".outE('" + DbName.Edge.UserDefinesMemberName + "')" +
                ".has('" + DbName.Edge.UserDefinesMember.AppId + "',Tokens.T.eq,_P)" +
                ".sideEffect{it.setProperty('" + DbName.Edge.UserDefinesMember.MemberType + "',_P);}" +
                ".inV" +
                ".outE('" + DbName.Edge.MemberDefinedByAppName + "').inV" +
                ".outE('" + DbName.Edge.AppDefinesMemberName + "')" +
                ".has('" + DbName.Edge.AppDefinesMember.UserId + "',Tokens.T.eq,_P)" +
                ".sideEffect{it.setProperty('" + DbName.Edge.AppDefinesMember.MemberType + "',_P);}" +
                ".inV;";

            var expectUpdateParams = new List <object> {
                vMem.VertexId,
                (byte)vNewMemTypeId,
                appId,
                (byte)vNewMemTypeId,
                userId,
                (byte)vNewMemTypeId
            };

            vMockData
            .Setup(x => x.Get <Member>(It.IsAny <IWeaverQuery>(), "Web-UpdateMemberType"))
            .Callback((IWeaverScript q, string n) =>
                      TestUtil.CheckWeaverScript(q, expectUpdateScript, "_P", expectUpdateParams))
            .Returns(vMem);

            ////

            Member result = vOper.Execute(vMockOpCtx.Object, vMem.VertexId, vNewMemTypeId);

            Assert.AreEqual(vMem, result, "Incorrect result.");
        }