Exemple #1
0
        public ActionResult PartyCreate(PartyModel model)
        {
            var service = new PartyService();
            var result  = service.CreateParty(model);

            return(RedirectToAction("GetAllParties", "Admin", null));
        }
Exemple #2
0
        public ActionResult GetAllParties()
        {
            var service = new PartyService();
            var model   = service.GetAllParties();

            return(View("Parties/Index", model));
        }
 private async Task DeleteItemsAsync(IEnumerable <PartyModel> models)
 {
     foreach (var model in models)
     {
         await PartyService.DeletePartyAsync(model);
     }
 }
        public void ValidContractAdded()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);
            var identifier = new MdmId { SystemName = "Test", Identifier = "A" };
            var message = new CreateMappingRequest
            {
                EntityId = 12,
                Mapping = identifier
            };

            var system = new MDM.SourceSystem { Name = "Test" };
            var mapping = new PartyMapping { System = system, MappingValue = "A" };
            validatorFactory.Setup(x => x.IsValid(It.IsAny<CreateMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PartyMapping>(identifier)).Returns(mapping);

            var party = new MDM.Party();
            repository.Setup(x => x.FindOne<MDM.Party>(12)).Returns(party);

            // Act
            var candidate = (PartyMapping)service.CreateMapping(message);

            // Assert
            Assert.AreSame(mapping, candidate);
            repository.Verify(x => x.Save(party));
            repository.Verify(x => x.Flush());
        }
Exemple #5
0
        /// <summary>
        /// 确定聚会
        /// </summary>
        public ActionResult ConfirmParty(int partyId, string code, string state)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(Content("无法获取当前用户信息。"));
            }
            else
            {
                var accessTokenInfo = WeChatHelper.WeChat.GetWeChatAccessTokenInfo_OAuth(code);

                try
                {
                    var confirmPartyInfo = PartyService.ConfirmParty(partyId, accessTokenInfo.openid);

                    var model = new ConfirmPartyViewModel
                    {
                        ConfirmPartyInfo = confirmPartyInfo
                    };

                    return(View(model));
                }
                catch (BasicSystemException ex)
                {
                    return(Content(ex.ToLocalize()));
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// 报名聚会
        /// </summary>
        public ActionResult ParticipateParty(int partyId, string code, string state)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(Content("无法获取当前用户信息。"));
            }
            else
            {
                var accessTokenInfo = WeChatHelper.WeChat.GetWeChatAccessTokenInfo_OAuth(code);

                try
                {
                    var participateCountInfo = PartyService.ParticipateParty(partyId, accessTokenInfo.openid);
                    if (participateCountInfo.ParticipateCount == participateCountInfo.MinIntoForce)
                    {
                        WeChatHelper.WeChat.SendCSTextMessage(participateCountInfo.InitiatorOpenId, string.Format(CommonSettings.DUOJUWECHATMESSAGE_PARTYFULLED_FORMAT, WeChatHelper.WeChat.ConvertOAuthUrl("http://wechat.duoju.us/Party/ConfirmParty/" + partyId, OauthScopes.SNSAPI_BASE, null)));
                    }

                    return(RedirectToAction("ViewParty", new { partyId = partyId, isReturn = true }));
                }
                catch (BasicSystemException ex)
                {
                    return(Content(ex.ToLocalize()));
                }
            }
        }
        public HttpResponseMessage InsertParty([FromBody] clsParty request)
        {
            LoggerFactory.LoggerInstance.LogDebug("Request Started for : " + request.PartyID + " Party name :" + request.PartyName);
            HttpResponseMessage response = new HttpResponseMessage();

            try
            {
                PartyService objComService = new PartyService();
                var          objResponse   = objComService.InsertParty(request);
                if (objResponse != null && objResponse.ToString() != "")
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, objResponse);
                    LoggerFactory.LoggerInstance.LogDebug("Request End for : " + request.PartyID + "   Party name :" + request.PartyName);
                }
                else
                {
                    response = Request.CreateErrorResponse(HttpStatusCode.NotFound, "No detail found  for   Party name : " + request.PartyName + ".");
                }
            }
            catch (Exception ex)
            {
                LoggerFactory.LoggerInstance.LogException(ex);
                response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error occured while getting   Party name " + request.PartyName + ".");
            }
            return(response);
        }
        public void EntityNotFound()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var message = new AmendMappingRequest
            {
                EntityId = 12,
                Mapping  = new MdmId {
                    SystemName = "Test", Identifier = "A"
                }
            };

            validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);

            // Act
            var candidate = service.UpdateMapping(message);

            // Assert
            Assert.IsNull(candidate);
        }
Exemple #9
0
        /// <summary>
        /// This updates the parties squad assignments, mainly used when a member joins or leaves.
        /// </summary>
        /// <param name="oAuthSession">The <see cref="OAuthSession"/> to use for authentication.</param>
        internal async Task UpdateSquadAssignments(OAuthSession oAuthSession)
        {
            // Initialise our variables
            var assignments = new List <RawSquadAssignment>();
            var index       = 0;

            // Add the current account to the list of assignments
            assignments.Add(new(oAuthSession.AccountId));

            // For each member in the party...
            foreach (var member in Members)
            {
                // If the member is our XMPP client, continue enumerating through the party's members.
                if (member.Id == oAuthSession.AccountId)
                {
                    continue;
                }

                // Increment our index and add the member to the list of assignments.
                index++;
                assignments.Add(new(member.Id, index));
            }

            // Update/set our meta to the list of assignments.
            Meta["Default:RawSquadAssignments_j"] = new RawSquadAssignments(assignments).ToString();

            // Update the party with the new squad assignments.
            await PartyService.UpdateParty(oAuthSession, this, new()
            {
                { "Default:RawSquadAssignments_j", Meta["Default:RawSquadAssignments_j"] }
            });
        }
Exemple #10
0
        public static void NpcDied(Npc npc)
        {
            var player = npc.Ai.GetKiller() as Player;

            if (player != null)
            {
                if (player.Party != null)
                {
                    foreach (Player member in PartyService.GetOnlineMembers(player.Party))
                    {
                        QuestEngine.OnPlayerKillNpc(member, npc);
                    }
                }
                else
                {
                    QuestEngine.OnPlayerKillNpc(player, npc);
                }

                player.Instance.OnNpcKill(player, npc);
            }

            if (npc.NpcTemplate.Size != NpcSize.Small)
            {
                npc.Ai.DealExp();
            }

            if (player != null)
            {
                MapService.CreateDrop(npc, player);
            }
        }
        /// <summary>
        /// Accepts a party invite.
        /// </summary>
        /// <param name="xmppClient">The <see cref="XMPPClient"/> to accept the invite for.</param>
        /// <exception cref="InvalidOperationException">Thrown if the invite is expired.</exception>
        public async Task Accept(XMPPClient xmppClient)
        {
            // If the expiry time has passed, this means the invite has expired.
            if (DateTime.Compare(DateTime.UtcNow, ExpiresAt) > 0)
            {
                IsExpired = true;
            }

            // If the invite has expired, throw an exception.
            if (IsExpired)
            {
                throw new InvalidOperationException($"Party invite to {PartyId} expired or was already accepted/declined!");
            }

            // If our XMPP client's party is not null, leave it.
            if (xmppClient.CurrentParty != null)
            {
                await PartyService.LeaveParty(xmppClient);
            }

            // Join the party of the invite, and delete the ping.
            await PartyService.JoinParty(xmppClient, this);

            await PartyService.DeletePingById(xmppClient.AuthSession, SentBy);

            // The invite was accepted, so it has now expired.
            IsExpired = true;
        }
Exemple #12
0
        public void TestCreateMoreParty()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
                IRepository<Employee, Guid> employeeRepository = new Repository<Employee, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHierarchyRepository = new Repository<PartyHierarchy, Guid>(store);
                Employee employee = new Employee()
                {
                    Name = "Bob",
                };

                Post post = new Post()
                {
                    Name = "總經理室副主管",
                };

                Post parentPost = postRepository.Query(q => q.Name == "總經理室主管").First();
                employeeRepository.SaveOrUpdate(employee);
                postRepository.SaveOrUpdate(post);

                PartyService partyService = new PartyService(partyHierarchyRepository);
                partyService.AddAccountability(parentPost, post);
                unitwork.SaveChanges();
                partyService.AddEmployeeToPost(post, employee);
                unitwork.SaveChanges();
            }
        }
Exemple #13
0
        public async Task <IHttpActionResult> AddNewParty(PartyModel party)
        {
            if (party == null)
            {
                return(BadRequest("Please provide valid inputs!"));
            }

            if (string.IsNullOrEmpty(party.Location))
            {
                return(BadRequest("Please provide valid location!"));
            }

            if (await AuthService.ValidateUserAndToken(party.Token, party.UserID, party.Email, party.Location))
            {
                if (await PartyService.PartyExists(party))
                {
                    return(BadRequest("Party Already Exists"));
                }
                else
                {
                    if (await PartyService.AddNewParty(party))
                    {
                        return(Ok("Party Added Successfully!"));
                    }
                    else
                    {
                        return(BadRequest("Party Adding Failed!"));
                    }
                }
            }
            else
            {
                return(Unauthorized());
            }
        }
Exemple #14
0
        public ActionResult PartyDelete(int id, PartyModel collection)
        {
            var service = new PartyService();

            service.DeleteParty(id);
            return(RedirectToAction("GetAllParties", "Admin", null));
        }
Exemple #15
0
        // GET: Experts/Delete/5
        public ActionResult PartyDelete(int id)
        {
            var service = new PartyService();
            var model   = service.GetParty(id);

            return(View("Parties/Delete", model));
        }
        public static void Main(string[] args)
        {
            // See https://support.microsoft.com/en-gb/help/821268/contention-poor-performance-and-deadlocks-when-you-make-calls-to-web-s
            // Experimentation shows we need the ThreadPool to always spin up threads for good performance under load
            ThreadPool.GetMaxThreads(out var workerThreads, out var ioThreads);
            ThreadPool.SetMinThreads(workerThreads, ioThreads);

            Parser.Default.ParseArguments <PartyServerCommandLineArgs>(args)
            .WithParsed(parsedArgs =>
            {
                parsedArgs.Validate();

                var spatialRefreshToken = Secrets.GetEnvSecret(SpatialRefreshTokenEnvironmentVariable);

                PartyDataModel.Defaults.MinMembers = (uint)parsedArgs.DefaultMinMembers;
                PartyDataModel.Defaults.MaxMembers = (uint)parsedArgs.DefaultMaxMembers;

                Log.Logger = new LoggerConfiguration()
                             .WriteTo.Console(new RenderedCompactJsonFormatter())
                             .Enrich.FromLogContext()
                             .CreateLogger();

                using (var server = GrpcBaseServer.Build(parsedArgs))
                    using (var memoryStoreManager = new RedisClientManager(parsedArgs.RedisConnectionString))
                    {
                        Log.Information($"Successfully connected to Redis at {parsedArgs.RedisConnectionString}");
                        server.AddInterceptor(new PlayerIdentityTokenValidatingInterceptor(
                                                  PlayerAuthServiceClient.Create(credentials: new PlatformRefreshTokenCredential(spatialRefreshToken)),
                                                  memoryStoreManager.GetRawClient(Database.CACHE)
                                                  ))
                        .AddInterceptor(new ExceptionMappingInterceptor(new Dictionary <Type, StatusCode>
                        {
                            { typeof(EntryNotFoundException), StatusCode.NotFound },
                            { typeof(EntryAlreadyExistsException), StatusCode.AlreadyExists },
                            { typeof(TransactionAbortedException), StatusCode.Unavailable }
                        }));
                        server.AddService(
                            PartyService.BindService(new PartyServiceImpl(memoryStoreManager)));
                        server.AddService(
                            InviteService.BindService(new InviteServiceImpl(memoryStoreManager)));
                        var serverTask = Task.Run(() => server.Start());
                        var signalTask = Task.Run(() => UnixSignal.WaitAny(new[] { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGTERM) }));
                        Task.WaitAny(serverTask, signalTask);

                        if (signalTask.IsCompleted)
                        {
                            Log.Information($"Received UNIX signal {signalTask.Result}");
                            Log.Information("Server shutting down...");
                            server.Shutdown();
                            serverTask.Wait();
                            Log.Information("Server stopped cleanly");
                        }
                        else
                        {
                            /* The server task has completed; we can just exit. */
                            Log.Information("The Party server has stopped itself or encountered an unhandled exception.");
                        }
                    }
            });
        }
Exemple #17
0
        public ActionResult Vote(VoteViewModel model, IFormFile photo)
        {
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(model.Name) && model.IsAttend)
                {
                    string filename = null;
                    if (photo != null)
                    {
                        var ext = Path.GetExtension(photo.FileName);
                        filename = $@"{Guid.NewGuid()}{ext}";
                        var path = Path.Combine(_env.WebRootPath, "images", filename);
                        using (var fileStream = new FileStream(path, FileMode.Create))
                        {
                            photo.CopyTo(fileStream);
                        }
                    }

                    PartyService.Vote(model.PartyId, model.Name, model.IsAttend, filename);

                    Logger.Info($"{model.Name} -> {PartyService.GetParty(model.PartyId).Name} : {model.IsAttend}");
                }

                return(RedirectToAction("Index", new { id = model.PartyId }));
            }

            var party      = PartyService.GetParty(model.PartyId);
            var attendants = PartyService.ListAttendants(party.Id).Select(x => (x.Name, x.Avatar)).ToList();
            var partyModel = new PartyDetailsViewModel {
                PartyId = party.Id, Date = party.Date, Title = party.Name, Location = party.Location, Attendants = attendants
            };

            return(View("Index", partyModel));
        }
Exemple #18
0
        public ActionResult PartyEdit(int id, PartyModel model)
        {
            var service = new PartyService();

            service.UpdateParty(model);
            return(RedirectToAction("GetAllParties", "Admin", null));
        }
        public void UnsuccessfulMatchReturnsNotFound()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var list = new List <PartyMapping>();

            repository.Setup(x => x.Queryable <PartyMapping>()).Returns(list.AsQueryable());
            validatorFactory.Setup(x => x.IsValid(It.IsAny <MappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);

            var request = new MappingRequest {
                SystemName = "Endur", Identifier = "A", ValidAt = SystemTime.UtcNow()
            };

            // Act
            var contract = service.Map(request);

            // Assert
            repository.Verify(x => x.Queryable <PartyMapping>());
            Assert.IsNotNull(contract, "Contract null");
            Assert.IsFalse(contract.IsValid, "Contract valid");
            Assert.AreEqual(ErrorType.NotFound, contract.Error.Type, "ErrorType difers");
        }
        public void VersionConflict()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var message = new AmendMappingRequest
            {
                MappingId = 12,
                Mapping   = new MdmId {
                    SystemName = "Test", Identifier = "A"
                },
                Version = 34
            };

            var party = new MDM.Party();

            party.AddDetails(new PartyDetails()
            {
                Timestamp = BitConverter.GetBytes(25L)
            });
            var mapping = new PartyMapping {
                Party = party
            };

            validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);
            repository.Setup(x => x.FindOne <PartyMapping>(12)).Returns(mapping);

            // Act
            service.UpdateMapping(message);
        }
        public void UnsuccessfulMatchReturnsNotFound()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var list = new List<PartyMapping>();
            repository.Setup(x => x.Queryable<PartyMapping>()).Returns(list.AsQueryable());

            var message = new GetRequest
            {
                EntityId = 0,
            };

            // Act
            var contract = service.Request(message);

            // Assert
            Assert.IsNotNull(contract, "Contract null");
            Assert.IsFalse(contract.IsValid, "Contract valid");
            Assert.AreEqual(ErrorType.NotFound, contract.Error.Type, "ErrorType difers");
        }
Exemple #22
0
        public IHttpActionResult Get()
        {
            PartyService partyService = CreatePartyService();
            var          parties      = partyService.GetParties();

            return(Ok(parties));
        }
Exemple #23
0
        private PartyService CreatePartyService()
        {
            var userId       = Guid.Parse(User.Identity.GetUserId());
            var partyService = new PartyService(userId);

            return(partyService);
        }
        public void UnsuccessfulMatchReturnsNotFound()
        {
            // Arrange
            var validatorFactory = new Mock <IValidatorEngine>();
            var mappingEngine    = new Mock <IMappingEngine>();
            var repository       = new Mock <IRepository>();
            var searchCache      = new Mock <ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var list = new List <PartyMapping>();

            repository.Setup(x => x.Queryable <PartyMapping>()).Returns(list.AsQueryable());

            var message = new GetRequest
            {
                EntityId = 0,
            };

            // Act
            var contract = service.Request(message);

            // Assert
            Assert.IsNotNull(contract, "Contract null");
            Assert.IsFalse(contract.IsValid, "Contract valid");
            Assert.AreEqual(ErrorType.NotFound, contract.Error.Type, "ErrorType difers");
        }
Exemple #25
0
        public ActionResult Vote(int partyId, string name, string isAttend)
        {
            PartyService.Vote(partyId, name, isAttend == "on");

            Logger.Info($"{name} -> {PartyService.GetParty(partyId).Title} : {isAttend}");

            return(RedirectToAction("Index", new { id = partyId }));
        }
Exemple #26
0
        // GET: Experts/Edit/5
        public ActionResult PartyEdit(int id)
        {
            var service = new PartyService();
            var model   = service.GetParty(id);

            return(View("Parties/Edit", model));
            //return RedirectToAction( "GetAllParties", "Admin", null );
        }
Exemple #27
0
        public ActionResult Vote(VoteViewModel model)
        {
            PartyService.Vote(model.PartyId, model.Name, model.IsAttend == "on");

            Logger.Info($"{model.Name} -> {PartyService.GetParty(model.PartyId).Title} : {model.IsAttend == "on"}");

            return(RedirectToAction("Index", new { id = model.PartyId }));
        }
Exemple #28
0
        /// <summary>
        /// Sets the custom matchmaking key for the current party with the provided key.
        /// </summary>
        /// <param name="oAuthSession">The <see cref="OAuthSession"/> to use for authentication.</param>
        /// <param name="key">The desired custom matchmaking key.</param>
        public async Task SetCustomMatchmakingKey(OAuthSession oAuthSession, string key = null)
        {
            Meta["Default:CustomMatchKey_s"] = key ?? "";

            await PartyService.UpdateParty(oAuthSession, this, new()
            {
                { "Default:CustomMatchKey_s", Meta["Default:CustomMatchKey_s"] }
            });
        }
Exemple #29
0
        public void GetListTest()
        {
            var partyService = new PartyService(new PartyRepository());
            var result       = partyService.GetList(new PagedRequestDto {
                Take = 20
            });

            Assert.AreEqual(20, result.Data.Count());
        }
Exemple #30
0
 public FortniteApi()
 {
     AccountService  = new();
     ChannelsService = new();
     EventsService   = new();
     FortniteService = new();
     FriendsService  = new();
     PartyService    = new();
 }
Exemple #31
0
        /// <summary>
        /// Sets the playlist for the current party with the provided playlist ID.
        /// </summary>
        /// <param name="oAuthSession">The <see cref="OAuthSession"/> to use for authentication.</param>
        /// <param name="playlistId">The playlist ID of the desired playlist.</param>
        public async Task SetPlaylist(OAuthSession oAuthSession, string playlistId)
        {
            Meta["Default:PlaylistData_j"] = new PlaylistDataMeta(playlistId).ToString();

            await PartyService.UpdateParty(oAuthSession, this, new()
            {
                { "Default:PlaylistData_j", Meta["Default:PlaylistData_j"] }
            });
        }
Exemple #32
0
        public DatabaseManager(DbModelContainer dbContext, Encryption encryption, PartyService partyService, VoterService voterService, CandidateService candidateService, StatisticService statisticService)
        {
            _dbContext = dbContext;

            Party     = partyService;
            Voter     = voterService;
            Candidate = candidateService;
            Statistic = statisticService;
        }
 private async Task <IList <PartyModel> > GetItemsAsync()
 {
     if (!ViewModelArgs.IsEmpty)
     {
         DataRequest <Data.Party> request = BuildDataRequest();
         return(await PartyService.GetPartiesAsync(request));
     }
     return(new List <PartyModel>());
 }
        public void NullRequestErrors()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            // Act
            service.Map(null);
        }
        public void NullContractInvalid()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            validatorFactory.Setup(x => x.IsValid(It.IsAny<object>(), It.IsAny<IList<IRule>>())).Returns(false);

            // Act
            service.CreateMapping(null);
        }
        public void InvalidContractNotSaved()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var contract = new EnergyTrading.MDM.Contracts.Sample.Party();

            validatorFactory.Setup(x => x.IsValid(It.IsAny<object>(), It.IsAny<IList<IRule>>())).Returns(false);

            // Act
            service.Create(contract);
        }
        public void EarlierVersionRaisesVersionConflict()
        {
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Party>(), It.IsAny<IList<IRule>>())).Returns(true);

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var cd = new EnergyTrading.MDM.Contracts.Sample.PartyDetails { Name = "Party 1" };
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) };
            var contract = new EnergyTrading.MDM.Contracts.Sample.Party { Details = cd, MdmSystemData = nexus };

            var details = new PartyDetails { Id = 2, Name = "Party 1" };
            var entity = new Party();
            entity.AddDetails(details);

            repository.Setup(x => x.FindOne<Party>(1)).Returns(entity);

            // Act
            service.Update(1, 1, contract);
        }
        public void EntityNotFound()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var cd = new EnergyTrading.MDM.Contracts.Sample.PartyDetails { Name = "Party 1" };
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) };
            var contract = new EnergyTrading.MDM.Contracts.Sample.Party { Details = cd, MdmSystemData = nexus };

            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Party>(), It.IsAny<IList<IRule>>())).Returns(true);

            // Act
            var response = service.Update(1, 1, contract);

            // Assert
            Assert.IsNotNull(response, "Response is null");
            Assert.IsFalse(response.IsValid, "Response is valid");
            Assert.AreEqual(ErrorType.NotFound, response.Error.Type, "ErrorType differs");
        }
        public void ValidDetailsSaved()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var identifier = new MdmId { SystemName = "Test", Identifier = "A" };
            var message = new AmendMappingRequest { MappingId = 12, Mapping = identifier, Version = 34 };

            var start = new DateTime(2000, 12, 31);
            var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(5));
            var s1 = new MDM.SourceSystem { Name = "Test" };
            var m1 = new PartyMapping { Id = 12, System = s1, MappingValue = "1", Version = 34UL.GetVersionByteArray(), Validity = new DateRange(start, DateUtility.MaxDate) };
            var m2 = new PartyMapping { Id = 12, System = s1, MappingValue = "1", Validity = new DateRange(start, finish) };

            // NB We deliberately bypasses the business logic
            var party = new MDM.Party();
            m1.Party = party;
            party.Mappings.Add(m1);

            validatorFactory.Setup(x => x.IsValid(It.IsAny<AmendMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);
            repository.Setup(x => x.FindOne<PartyMapping>(12)).Returns(m1);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PartyMapping>(identifier)).Returns(m2);

            // Act
            service.UpdateMapping(message);

            // Assert
            // NB Don't verify result of Update - already covered by PartyMappingFixture
            repository.Verify(x => x.Save(party));
            repository.Verify(x => x.Flush());
        }
        public void ValidContractIsSaved()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var party = new Party();
            var contract = new EnergyTrading.MDM.Contracts.Sample.Party();

            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Party>(), It.IsAny<IList<IRule>>())).Returns(true);
            mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.Party, Party>(contract)).Returns(party);

            // Act
            var expected = service.Create(contract);

            // Assert
            Assert.AreSame(expected, party, "Party differs");
            repository.Verify(x => x.Add(party));
            repository.Verify(x => x.Flush());
        }
        public void EntityNotFound()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var message = new CreateMappingRequest
                {
                    EntityId = 12,
                    Mapping = new MdmId { SystemName = "Test", Identifier = "A" }
                };

            validatorFactory.Setup(x => x.IsValid(It.IsAny<CreateMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);

            // Act
            var candidate = service.CreateMapping(message);

            // Assert
            Assert.IsNull(candidate);
        }
        public void ValidDetailsSaved()
        {
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            // Contract
            var cd = new EnergyTrading.MDM.Contracts.Sample.PartyDetails { Name = "Party 1" };
            var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) };
            var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" };
            var contract = new EnergyTrading.MDM.Contracts.Sample.Party { Details = cd, MdmSystemData = nexus };
            contract.Identifiers.Add(identifier);

            // Domain
            var system = new SourceSystem { Name = "Test" };
            var mapping = new PartyMapping { System = system, MappingValue = "A" };
            var d1 = new PartyDetails { Id = 1, Name = "Party 1", Timestamp = 74UL.GetVersionByteArray() };
            var entity = new Party();
            entity.AddDetails(d1);

            var d2 = new PartyDetails { Name = "Party 1" };
            var range = new DateRange(new DateTime(2012, 1, 1), DateTime.MaxValue);

            validatorFactory.Setup(x => x.IsValid(It.IsAny<CreateMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);
            validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Party>(), It.IsAny<IList<IRule>>())).Returns(true);

            repository.Setup(x => x.FindOne<Party>(1)).Returns(entity);

            mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.PartyDetails, PartyDetails>(cd)).Returns(d2);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.SystemData, DateRange>(nexus)).Returns(range);
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PartyMapping>(identifier)).Returns(mapping);

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            // Act
            service.Update(1, 74, contract);

            // Assert
            Assert.AreEqual(2, entity.Details.Count, "Details count differs");
            Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs");
            repository.Verify(x => x.Save(entity));
            repository.Verify(x => x.Flush());
        }
Exemple #43
0
        public void TestGetPostsOfEmployee()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
                PartyService partyService = new PartyService();
                Party emp = partyRepository.Query(s => s.Name == "Bob").First();
                var parties = partyService.GetPostsOf(emp.Id);

                Assert.AreEqual(1, parties.Count());
                Assert.AreEqual("總經理室副主管", parties.First().Name);
            }
        }
Exemple #44
0
        public void TestGetEmployeesOfPost()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
                PartyService partyService = new PartyService();
                Party post = partyRepository.Query(s => s.Name == "總經理室主管").First();
                var employees = partyService.GetEmployeesIn(post.Id);

                Assert.AreEqual(1, employees.Count());
            }
        }
        public void SuccessMatch()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            // Domain details
            var system = new MDM.SourceSystem { Name = "Endur" };
            var mapping = new PartyMapping
                {
                    System = system,
                    MappingValue = "A",
                };
            var targetSystem = new MDM.SourceSystem { Name = "Trayport" };
            var targetMapping = new PartyMapping
                {
                    System = targetSystem,
                    MappingValue = "B",
                    IsDefault = true
                };
            var details = new MDM.PartyDetails
                {
                    Name = "Party 1"
                };
            var party = new MDM.Party
                {
                    Id = 1
                };
            party.AddDetails(details);
            party.ProcessMapping(mapping);
            party.ProcessMapping(targetMapping);

            // Contract details
            var targetIdentifier = new MdmId
                {
                    SystemName = "Trayport",
                    Identifier = "B"
                };

            mappingEngine.Setup(x => x.Map<PartyMapping, MdmId>(targetMapping)).Returns(targetIdentifier);

            var list = new List<PartyMapping> { mapping };
            repository.Setup(x => x.Queryable<PartyMapping>()).Returns(list.AsQueryable());

            var request = new CrossMappingRequest
            {
                SystemName = "Endur",
                Identifier = "A",
                TargetSystemName = "trayport",
                ValidAt = SystemTime.UtcNow(),
                Version = 1
            };

            // Act
            var response = service.CrossMap(request);
            var candidate = response.Contract;

            // Assert
            Assert.IsNotNull(response, "Contract null");
            Assert.IsNotNull(candidate, "Mapping null");
            Assert.AreEqual(1, candidate.Mappings.Count, "Identifier count incorrect");
            Assert.AreSame(targetIdentifier, candidate.Mappings[0], "Different identifier assigned");
        }
Exemple #46
0
        public void TestCreateParty()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
                //用partyRepository也可以存進去,不知差別在哪
                IRepository<Employee, Guid> employeeRepository = new Repository<Employee, Guid>(store);
                IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHierarchyRepository = new Repository<PartyHierarchy, Guid>(store);
                Employee employee = new Employee()
                {
                    Name = "Allen"
                };

                Post post = new Post()
                {
                    Name = "總經理室主管"
                };

                employeeRepository.SaveOrUpdate(employee);
                postRepository.SaveOrUpdate(post);

                PartyService partyService = new PartyService(partyHierarchyRepository);
                partyService.AddEmployeeToPost(post,employee);

                unitwork.SaveChanges();
            }
        }
Exemple #47
0
        public void TestGetAllChildAccountParties()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
                PartyService partyService = new PartyService();
                Party post = partyRepository.Query(s => s.Name == "總經理室主管").First();
                var posts = partyService.GetAllChildAccountParties(post.Id);

                Assert.AreEqual(1, posts.Count());
            }
        }
        public void UnsuccessfulMatchReturnsNotFound()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var list = new List<PartyMapping>();
            repository.Setup(x => x.Queryable<PartyMapping>()).Returns(list.AsQueryable());
            validatorFactory.Setup(x => x.IsValid(It.IsAny<MappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);

            var request = new MappingRequest { SystemName = "Endur", Identifier = "A", ValidAt = SystemTime.UtcNow() };

            // Act
            var contract = service.Map(request);

            // Assert
            repository.Verify(x => x.Queryable<PartyMapping>());
            Assert.IsNotNull(contract, "Contract null");
            Assert.IsFalse(contract.IsValid, "Contract valid");
            Assert.AreEqual(ErrorType.NotFound, contract.Error.Type, "ErrorType difers");
        }
        public void SuccessMatch()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            // Domain details
            var start = new DateTime(1999, 12, 31);
            var finish = new DateTime(2020, 1, 1);
            var system = new SourceSystem { Name = "Endur" };
            var mapping = new PartyMapping
                {
                    System = system,
                    MappingValue = "A"
                };
            var details = new PartyDetails
                {
                    Name = "Party 1",
                    Validity = new DateRange(start, finish)
                };
            var party = new Party
                {
                    Id = 1
                };
            party.AddDetails(details);
            party.ProcessMapping(mapping);

            // Contract details
            var identifier = new EnergyTrading.Mdm.Contracts.MdmId
                {
                    SystemName = "Endur",
                    Identifier = "A"
                };
            var cDetails = new EnergyTrading.MDM.Contracts.Sample.PartyDetails
                {
                    Name = "Party 1"
                };

            mappingEngine.Setup(x => x.Map<PartyMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)).Returns(identifier);
            mappingEngine.Setup(x => x.Map<PartyDetails, EnergyTrading.MDM.Contracts.Sample.PartyDetails>(details)).Returns(cDetails);
            validatorFactory.Setup(x => x.IsValid(It.IsAny<MappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);

            var list = new List<PartyMapping> { mapping };
            repository.Setup(x => x.Queryable<PartyMapping>()).Returns(list.AsQueryable());

            var request = new MappingRequest
            {
                SystemName = "Endur",
                Identifier = "A",
                ValidAt = SystemTime.UtcNow(),
                Version = 1
            };

            // Act
            var response = service.Map(request);
            var candidate = response.Contract;

            // Assert
            repository.Verify(x => x.Queryable<PartyMapping>());

            Assert.IsTrue(response.IsValid);
            Assert.IsNotNull(candidate, "Contract null");

            mappingEngine.Verify(x => x.Map<PartyMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping));
            mappingEngine.Verify(x => x.Map<PartyDetails, EnergyTrading.MDM.Contracts.Sample.PartyDetails>(details));

            Assert.AreEqual(2, candidate.Identifiers.Count, "Identifier count incorrect");
            // NB This is order dependent
            Assert.AreSame(identifier, candidate.Identifiers[1], "Different identifier assigned");
            Assert.AreSame(cDetails, candidate.Details, "Different details assigned");
            Assert.AreEqual(start, candidate.MdmSystemData.StartDate, "Start date differs");
            Assert.AreEqual(finish, candidate.MdmSystemData.EndDate, "End date differs");
        }
        private void LoadParty(PartyService.PartySummary partySummary)
        {
            try
            {
                formBusyIndicator.IsBusy = true;

                CheckBusyAskCancel();

                this.webClient = app.ServiceGet(
                    string.Format("party/{0}", partySummary.Id), PartyLoadCompleted);

            }
            catch (Exception ex)
            {
                formBusyIndicator.IsBusy = false;
                MessageBox.Show(ex.Message, "Loading", MessageBoxButton.OK);
            }
        }
Exemple #51
0
        public void TestAddParty()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHireRepository = new Repository<PartyHierarchy, Guid>(store);

                Post post1 = new Post() { Name = "總經理室主管" };
                Post post2 = new Post() { Name = "總經理室副主管" };
                Post post3 = new Post() { Name = "總經理室秘書" };
                Post post4 = new Post() { Name = "人資部主管" };
                Post post5 = new Post() { Name = "人資部副主管" };
                Post post6 = new Post() { Name = "企畫課主管" };
                Post post7 = new Post() { Name = "企畫課副主管" };
                Post post8 = new Post() { Name = "企畫課成員" };
                Post post9 = new Post() { Name = "管理課主管" };
                Post post10 = new Post() { Name = "管理課副主管" };
                Post post11 = new Post() { Name = "管理課成員" };
                Post post12 = new Post() { Name = "業務部主管" };
                Post post13 = new Post() { Name = "業務部副主管" };
                Post post14 = new Post() { Name = "業務一課主管" };
                Post post15 = new Post() { Name = "業務一課副主管" };
                Post post16 = new Post() { Name = "業務一課成員" };

                postRepository.SaveOrUpdate(post1);
                postRepository.SaveOrUpdate(post2);
                postRepository.SaveOrUpdate(post3);
                postRepository.SaveOrUpdate(post4);
                postRepository.SaveOrUpdate(post5);
                postRepository.SaveOrUpdate(post6);
                postRepository.SaveOrUpdate(post7);
                postRepository.SaveOrUpdate(post8);
                postRepository.SaveOrUpdate(post9);
                postRepository.SaveOrUpdate(post10);
                postRepository.SaveOrUpdate(post11);
                postRepository.SaveOrUpdate(post12);
                postRepository.SaveOrUpdate(post13);
                postRepository.SaveOrUpdate(post14);
                postRepository.SaveOrUpdate(post15);
                postRepository.SaveOrUpdate(post16);

                unitwork.SaveChanges();

                PartyService service = new PartyService(partyHireRepository);
                service.AddAccountability(post1, post2);
                unitwork.SaveChanges();
                service.AddAccountability(post1, post3);
                unitwork.SaveChanges();
                service.AddAccountability(post1, post4);
                unitwork.SaveChanges();
                service.AddAccountability(post1, post12);
                unitwork.SaveChanges();
                service.AddAccountability(post4, post5);
                unitwork.SaveChanges();
                service.AddAccountability(post4, post6);
                unitwork.SaveChanges();
                service.AddAccountability(post4, post9);
                unitwork.SaveChanges();
                service.AddAccountability(post6, post7);
                unitwork.SaveChanges();
                service.AddAccountability(post6, post8);
                unitwork.SaveChanges();
                service.AddAccountability(post9, post10);
                unitwork.SaveChanges();
                service.AddAccountability(post9, post11);
                unitwork.SaveChanges();
                service.AddAccountability(post12, post13);
                unitwork.SaveChanges();
                service.AddAccountability(post12, post14);
                unitwork.SaveChanges();
                service.AddAccountability(post14, post15);
                unitwork.SaveChanges();
                service.AddAccountability(post14, post16);
                unitwork.SaveChanges();
            }
        }
Exemple #52
0
        public void TestAddEmployeeToPost()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Employee, Guid> empRepository = new Repository<Employee, Guid>(store);
                IRepository<Post, Guid> roleRepository = new Repository<Post, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHireRepository = new Repository<PartyHierarchy, Guid>(store);

                Employee prt1 = new Employee() { Name = "Allen" };
                Employee prt2 = new Employee() { Name = "Bob" };
                Employee prt3 = new Employee() { Name = "Cary" };
                Employee prt4 = new Employee() { Name = "David" };
                Employee prt5 = new Employee() { Name = "Edward" };
                Employee prt6 = new Employee() { Name = "Fred" };
                Employee prt7 = new Employee() { Name = "Gallon" };
                Employee prt8 = new Employee() { Name = "Hellen" };
                Employee prt9 = new Employee() { Name = "Ian" };
                Employee prt10 = new Employee() { Name = "Ivy" };
                Employee prt11 = new Employee() { Name = "Jay" };
                Employee prt12 = new Employee() { Name = "Kalad" };
                Employee prt13 = new Employee() { Name = "Larry" };
                Employee prt14 = new Employee() { Name = "Moppies" };
                Employee prt15 = new Employee() { Name = "Nana" };
                Employee prt16 = new Employee() { Name = "Outu" };

                empRepository.SaveOrUpdate(prt1);
                empRepository.SaveOrUpdate(prt2);
                empRepository.SaveOrUpdate(prt4);
                empRepository.SaveOrUpdate(prt5);
                empRepository.SaveOrUpdate(prt6);
                empRepository.SaveOrUpdate(prt7);
                empRepository.SaveOrUpdate(prt8);
                empRepository.SaveOrUpdate(prt9);
                empRepository.SaveOrUpdate(prt10);
                empRepository.SaveOrUpdate(prt11);
                empRepository.SaveOrUpdate(prt12);
                empRepository.SaveOrUpdate(prt13);
                empRepository.SaveOrUpdate(prt14);
                empRepository.SaveOrUpdate(prt15);
                empRepository.SaveOrUpdate(prt16);

                PartyService service = new PartyService(partyHireRepository);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室主管").First(), prt1);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室副主管").First(), prt2);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室秘書").First(), prt3);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "人資部主管").First(), prt4);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "人資部副主管").First(), prt5);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課主管").First(), prt6);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課副主管").First(), prt7);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課成員").First(), prt8);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課主管").First(), prt9);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課副主管").First(), prt10);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課成員").First(), prt11);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務部主管").First(), prt12);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務部副主管").First(), prt13);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課主管").First(), prt14);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課副主管").First(), prt15);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課成員").First(), prt16);
                unitwork.SaveChanges();
            }
        }
        public void VersionConflict()
        {
            // Arrange
            var validatorFactory = new Mock<IValidatorEngine>();
            var mappingEngine = new Mock<IMappingEngine>();
            var repository = new Mock<IRepository>();
            var searchCache = new Mock<ISearchCache>();

            var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var message = new AmendMappingRequest
            {
                MappingId = 12,
                Mapping = new MdmId { SystemName = "Test", Identifier = "A" },
                Version = 34
            };

            var party = new MDM.Party();
            party.AddDetails(new PartyDetails() { Timestamp = BitConverter.GetBytes(25L) });
            var mapping = new PartyMapping { Party =  party };

            validatorFactory.Setup(x => x.IsValid(It.IsAny<AmendMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true);
            repository.Setup(x => x.FindOne<PartyMapping>(12)).Returns(mapping);

            // Act
            service.UpdateMapping(message);
        }