//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public override void SetUp() { base.SetUp(); vNewAppId = 685239856293; vNewMemId = 123235332; vAppCmd = "appCmd"; vMemCmd = "memCmd"; vSharpflakeQueue = new Queue <long>(new[] { vNewAppId, vNewMemId }); MockOpCtx.Setup(x => x.GetSharpflakeId <Vertex>()).Returns(vSharpflakeQueue.Dequeue); MockOpCtx.SetupGet(x => x.UtcNow).Returns(new DateTime(9999999999)); MockOpCtx.SetupGet(x => x.Code32).Returns("123456789012345678901234567890ab"); vCmdIdQueue = new Queue <string>(new[] { vAppCmd, vMemCmd }); MockAcc.Setup(x => x.GetLatestCommandId()).Returns(vCmdIdQueue.Dequeue); }
public void Execute() { const string name = "Test App"; const long creatorMemId = 123523532; const long userId = 12316232336666; ICreateOperationBuilder build = MockBuild.Object; CreateOperationTasks tasks = MockTasks.Object; var expectApp = new App(); var expectMem = new Member(); IWeaverVarAlias <App> appAlias = new WeaverVarAlias <App>("appAlias"); IWeaverVarAlias <Member> memAlias = new WeaverVarAlias <Member>("memAlias"); MockBuild .Setup(x => x.StartSession()) .Callback(CheckCallIndex("StartSession")); //// Add App MockTasks .Setup(x => x.FindDuplicateAppNameKey(build, ItIsVert <App>(vNewAppId))) .Callback(CheckCallIndex("FindDuplicateAppNameKey")); int addAppIndex = CallsAdded; MockTasks .Setup(x => x.AddApp(build, ItIsVert <App>(vNewAppId), out appAlias)) .Callback(CheckCallIndex("AddApp")); //// Add Member MockTasks .Setup(x => x.FindDuplicateMember(build, userId, vNewAppId)) .Callback(CheckCallIndex("FindDuplicateMember")); int addMemIndex = CallsAdded; MockTasks .Setup(x => x.AddMember(build, ItIsVert <Member>(vNewMemId), out memAlias)) .Callback(CheckCallIndex("AddMember")); //// Add App edges MockTasks .Setup(x => x.AddArtifactCreatedByMember( build, ItIsVert <App>(vNewAppId), It.Is <CreateFabApp>(c => c.CreatedByMemberId == creatorMemId), It.Is <IWeaverVarAlias <Artifact> >(a => a.Name == appAlias.Name) )) .Callback(CheckCallIndex("AddArtifactCreatedByMember")); //// Add Member edges MockTasks .Setup(x => x.AddMemberDefinedByApp( build, ItIsVert <Member>(vNewMemId), It.Is <CreateFabMember>(c => c.DefinedByAppId == vNewAppId), It.Is <IWeaverVarAlias <Member> >(a => a.Name == memAlias.Name) )) .Callback(CheckCallIndex("AddMemberDefinedByApp")); MockTasks .Setup(x => x.AddMemberDefinedByUser( build, ItIsVert <Member>(vNewMemId), It.Is <CreateFabMember>(c => c.DefinedByUserId == userId), It.Is <IWeaverVarAlias <Member> >(a => a.Name == memAlias.Name) )) .Callback(CheckCallIndex("AddMemberDefinedByUser")); //// Finish setup MockBuild .Setup(x => x.CommitAndCloseSession()) .Callback(CheckCallIndex("CommitAndCloseSession")); MockAcc.Setup(x => x.Execute(typeof(CreateAppAccountOperation).Name)) .Returns(MockRes.Object); MockRes.Setup(x => x.GetCommandIndexByCmdId(vAppCmd)).Returns(addAppIndex); MockRes.Setup(x => x.GetCommandIndexByCmdId(vMemCmd)).Returns(addMemIndex); MockRes.Setup(x => x.ToElementAt <App>(addAppIndex, 0)).Returns(expectApp); MockRes.Setup(x => x.ToElementAt <Member>(addMemIndex, 0)).Returns(expectMem); //// Execute var op = new CreateAppAccountOperation(); CreateAppAccountOperation.Result result = op.Execute(MockOpCtx.Object, build, tasks, name, creatorMemId, userId); Assert.NotNull(result, "Result should be filled."); Assert.AreEqual(CreateAppAccountOperation.ResultStatus.Success, result.Status, "Incorrect Status"); Assert.AreEqual(expectApp, result.NewApp, "Incorrect NewApp."); Assert.AreEqual(expectMem, result.NewMember, "Incorrect NewMember."); }
public void Execute() { const string email = "*****@*****.**"; const string username = "******"; const string password = "******"; const long fabAppId = (long)SetupAppId.FabSys; ICreateOperationBuilder build = MockBuild.Object; CreateOperationTasks tasks = MockTasks.Object; var expectUser = new User(); var expectMem = new Member(); var expectEmail = new Email(); IWeaverVarAlias <User> userAlias = new WeaverVarAlias <User>("userAlias"); IWeaverVarAlias <Member> memAlias = new WeaverVarAlias <Member>("memAlias"); IWeaverVarAlias <Email> emailAlias = new WeaverVarAlias <Email>("emailAlias"); MockData.Setup(x => x.Get <Email>(It.IsAny <IWeaverQuery>(), typeof(CreateUserAccountOperation).Name + "-FindDuplicateEmail")) .Returns((Email)null); MockBuild .Setup(x => x.StartSession()) .Callback(CheckCallIndex("StartSession")); //// Add App MockTasks .Setup(x => x.FindDuplicateUserNameKey(build, ItIsVert <User>(vNewUserId))) .Callback(CheckCallIndex("FindDuplicateUserNameKey")); int addAppIndex = CallsAdded; MockTasks .Setup(x => x.AddUser(build, ItIsVert <User>(vNewUserId), out userAlias)) .Callback(CheckCallIndex("AddUser")); //// Add Member MockTasks .Setup(x => x.FindDuplicateMember(build, vNewUserId, fabAppId)) .Callback(CheckCallIndex("FindDuplicateMember")); int addMemIndex = CallsAdded; MockTasks .Setup(x => x.AddMember(build, ItIsVert <Member>(vNewMemId), out memAlias)) .Callback(CheckCallIndex("AddMember")); //// Add Email int addEmailIndex = CallsAdded; MockTasks .Setup(x => x.AddEmail(build, ItIsVert <Email>(vNewEmailId), out emailAlias)) .Callback(CheckCallIndex("AddEmail")); //// Add App edges MockTasks .Setup(x => x.AddArtifactCreatedByMember( build, ItIsVert <User>(vNewUserId), It.Is <CreateFabUser>(c => c.CreatedByMemberId == vNewMemId), It.Is <IWeaverVarAlias <Artifact> >(a => a.Name == userAlias.Name) )) .Callback(CheckCallIndex("AddArtifactCreatedByMember")); //// Add Member edges MockTasks .Setup(x => x.AddMemberDefinedByApp( build, ItIsVert <Member>(vNewMemId), It.Is <CreateFabMember>(c => c.DefinedByAppId == fabAppId), It.Is <IWeaverVarAlias <Member> >(a => a.Name == memAlias.Name) )) .Callback(CheckCallIndex("AddMemberDefinedByApp")); MockTasks .Setup(x => x.AddMemberDefinedByUser( build, ItIsVert <Member>(vNewMemId), It.Is <CreateFabMember>(c => c.DefinedByUserId == vNewUserId), It.Is <IWeaverVarAlias <Member> >(a => a.Name == memAlias.Name) )) .Callback(CheckCallIndex("AddMemberDefinedByUser")); //// Add Email edges MockTasks .Setup(x => x.AddEmailUsedByArtifact( build, ItIsVert <Email>(vNewEmailId), It.Is <CreateFabEmail>(c => c.UsedByArtifactId == vNewUserId), It.Is <IWeaverVarAlias <Email> >(a => a.Name == emailAlias.Name) )) .Callback(CheckCallIndex("AddEmailUsedByArtifact")); //// Finish setup MockBuild .Setup(x => x.CommitAndCloseSession()) .Callback(CheckCallIndex("CommitAndCloseSession")); MockAcc.Setup(x => x.Execute(typeof(CreateUserAccountOperation).Name)) .Returns(MockRes.Object); MockRes.Setup(x => x.GetCommandIndexByCmdId(vUserCmd)).Returns(addAppIndex); MockRes.Setup(x => x.GetCommandIndexByCmdId(vMemCmd)).Returns(addMemIndex); MockRes.Setup(x => x.GetCommandIndexByCmdId(vEmailCmd)).Returns(addEmailIndex); MockRes.Setup(x => x.ToElementAt <User>(addAppIndex, 0)).Returns(expectUser); MockRes.Setup(x => x.ToElementAt <Member>(addMemIndex, 0)).Returns(expectMem); MockRes.Setup(x => x.ToElementAt <Email>(addEmailIndex, 0)).Returns(expectEmail); //// Execute var op = new CreateUserAccountOperation(); CreateUserAccountOperation.Result result = op.Execute(MockOpCtx.Object, build, tasks, email, username, password); Assert.NotNull(result, "Result should be filled."); Assert.AreEqual(CreateUserAccountOperation.ResultStatus.Success, result.Status, "Incorrect Status"); Assert.AreEqual(expectUser, result.NewUser, "Incorrect NewApp."); Assert.AreEqual(expectMem, result.NewMember, "Incorrect NewMember."); Assert.AreEqual(expectEmail, result.NewEmail, "Incorrect NewEmail."); }