Esempio n. 1
0
    public void initialize()
    {
        mainUI         = GameObject.Find("MainUI").GetComponent <MainUIViewPresenter>();
        turnModel      = new EncounterTurnModel();
        encounterModel = new EncounterModel();
        positionFinder = GameObject.Find("PositionFinder").GetComponent <PositionFinder>();
        unitController = new UnitController();

        // This needs to happen before we init the turn model
        initEvents();

        unitController.initialize();
        turnModel.initialize();
    }
Esempio n. 2
0
        public bool InsertEncounterAndItem(EncounterModel em)
        {
            //Mappers
            EncounterEntity ee = new EncounterEntity();

            ee.Id           = em.Id;
            ee.Name         = em.Name;
            ee.IdInstance   = em.IdInstance;
            ee.Media        = em.Media;
            ee.ItemEntities = new List <ItemEntity>();


            foreach (var item in em.Items)
            {
                //ee.ItemEntities.Add(new ItemEntity()
                //{
                //    Id = item.Id,
                //    Name = item.Name,
                //    Type = item.Type,
                //    SubType = item.SubType,
                //    CreatureName = item.CreatureName,
                //    Icon = item.Icon,
                //    Media = item.Media,
                //});

                ItemEntity ie = new ItemEntity()
                {
                    Id           = item.Id,
                    Name         = item.Name,
                    Type         = item.Type,
                    SubType      = item.SubType,
                    CreatureName = item.CreatureName,
                    Icon         = item.Icon,
                    Media        = item.Media,
                };

                this._itemRepo.Insert(ie);

                EncounterItemEntity encounterItemEntity = new EncounterItemEntity()
                {
                    IdEncounter = em.Id,
                    IdItem      = item.Id,
                };


                this._encounterItemRepo.Insert(encounterItemEntity);
            }

            return(_encounterRepo.Insert(ee));
        }
Esempio n. 3
0
        public List <EncounterModel> GetEncountersByIdInstance(int id)
        {
            List <EncounterModel>  ems = new List <EncounterModel>();
            List <EncounterEntity> ees = ((EncounterRepository)_encounterRepo).GetByIdInstance(id);

            foreach (var ee in ees)
            {
                EncounterModel em = new EncounterModel();
                em.Id         = ee.Id;
                em.Name       = ee.Name;
                em.IdInstance = ee.IdInstance;
                em.Media      = ee.Media;
                ems.Add(em);
            }

            return(ems);
        }
Esempio n. 4
0
        public async Task <List <EncounterModel> > GetEncountersByInstanceId(int idInstance, List <int> idItems)
        {
            List <EncounterModel> encModels = new List <EncounterModel>();

            //On récupère les instances name grâce à la fct getInstanceById
            var resInstance = await InstanceRepoAPI.GetInstanceById(staticNamespace, localeUS, idInstance);


            var resEnc = await EncounterRepoAPI.SearchEncounter(staticNamespace, locale, resInstance.name);

            if (resEnc != null)
            {
                foreach (ResultEncounter result in resEnc.results)
                {
                    EncounterModel encModel = new EncounterModel();

                    encModel.Id         = result.data.id;
                    encModel.Name       = result.data.name.fr_FR;
                    encModel.IdInstance = result.data.instance.id;
                    encModel.IdItems    = new List <int>();
                    int idMedia          = result.data.creatures[0].creature_display.id;
                    var resMediaCreature = await ItemRepoAPI.GetMediaCreatureById(staticNamespace, localeUS, idMedia);

                    encModel.Media = resMediaCreature.assets[0].value;


                    foreach (var item in result.data.items)
                    {
                        encModel.IdItems.Add(item.item.id);

                        //Je remplis une liste d'idItems récupérée de l'extérieur pour pouvoir
                        //remplir ma table ITEM indépendamment des boss (récupérer tous les id dans une liste,
                        //Enlever les doublons, récupérer les ITEMMODEL avec "GetItemsByID" et les insérer dans la db"
                        idItems.Add(item.item.id);
                    }

                    encModels.Add(encModel);
                }
            }


            return(encModels);
        }
        private void CreateComponent(EncounterModel ptEncounter, ClinicalDocument clinicalDoc, III hl7III)
        {
            hl7Body          = clinicalDoc.Component.AsStructuredBody;
            functionalStatus = hl7Body.Component.Append();
            hl7III           = functionalStatus.Section.TemplateId.Append();
            if (ptEncounter.root != null)
            {
                hl7III.Init(ptEncounter.root);
            }

            //if (dictionary.ContainsKey(Root2))
            //{
            //    hl7III = functionalStatus.Section.TemplateId.Append;
            //    hl7III.Init(dictionary.Item(Root2));
            //}

            if (ptEncounter.code != null)
            {
                functionalStatus.Section.Code.Code = ptEncounter.code;
            }

            if (ptEncounter.codeSystem != null)
            {
                functionalStatus.Section.Code.CodeSystem = ptEncounter.codeSystem;
            }

            if (ptEncounter.codeSystemName != null)
            {
                functionalStatus.Section.Code.CodeSystemName = ptEncounter.codeSystemName;
            }

            if (ptEncounter.displayName != null)
            {
                functionalStatus.Section.Code.DisplayName = ptEncounter.displayName;
            }

            if (ptEncounter.title != null)
            {
                functionalStatus.Section.Title.Text = ptEncounter.title;
            }
        }
Esempio n. 6
0
        public async Task <EncounterModel> GenerateAsync(EncounterOption option)
        {
            ValidateOption(option);
            PartyLevel = option.PartyLevel;
            PartySize  = option.PartySize;
            XpList     = new List <KeyValuePair <Difficulty, int> >()
            {
                new KeyValuePair <Difficulty, int>(Difficulty.Easy, _thresholds[PartyLevel, 0] * PartySize),
                new KeyValuePair <Difficulty, int>(Difficulty.Medium, _thresholds[PartyLevel, 1] * PartySize),
                new KeyValuePair <Difficulty, int>(Difficulty.Hard, _thresholds[PartyLevel, 2] * PartySize),
                new KeyValuePair <Difficulty, int>(Difficulty.Deadly, _thresholds[PartyLevel, 3] * PartySize)
            };
            try
            {
                Monsters = new List <Monster>(MonsterLoader.Instance.MonsterList);
                var sumxp      = CalcSumXP((int)Difficulty.Deadly);
                var monsterXps = new SortedSet <int>();

                if (option.MonsterTypes.Any())
                {
                    var selectedMonsters = option.MonsterTypes.Select(m => m.ToString().ToLower());
                    Monsters = Monsters.Where(m => selectedMonsters.Any(m.Type.ToLower().Equals)).ToList();
                }

                if (option.Difficulty.HasValue)
                {
                    sumxp = _thresholds[option.PartyLevel, (int)option.Difficulty.Value] * option.PartySize;
                }

                foreach (var monster in Monsters)
                {
                    monsterXps.Add(_challengeRatingXP[_challengeRating.IndexOf(monster.Challenge_Rating)]);
                }

                CheckPossible(sumxp, monsterXps);

                var result       = new EncounterModel();
                var maxTryNumber = 5000;
                await Task.Run(() =>
                {
                    while (result.Encounters.Count < option.Count && maxTryNumber > 0)
                    {
                        try
                        {
                            result.Encounters.Add(GetMonster(option.Difficulty));
                            maxTryNumber--;
                        }
                        catch (ServiceException)
                        {
                            maxTryNumber--;
                            continue;
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                });

                result.Encounters.RemoveAll(ed => ed == null); // cleanup if needed
                result.SumXp = result.Encounters.Sum(ed => ed.XP);

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Generate encounter failed.");
                throw new ServiceException(ex.Message, ex);
            }
        }
Esempio n. 7
0
        private void Copy()
        {
            if (_selectedEncounter != null)
            {
                bool copyEncounter = true;

                if (_encounterEditViewModel != null)
                {
                    if (_editHasUnsavedChanges)
                    {
                        string body = String.Format("{0} has unsaved changes.{1}What would you like to do?",
                                                    _selectedEncounter.Name, Environment.NewLine + Environment.NewLine);
                        string accept = "Save and Continue";
                        string reject = "Discard Changes";
                        string cancel = "Cancel Navigation";
                        bool?  result = _dialogService.ShowConfirmationDialog("Unsaved Changes", body, accept, reject, cancel);

                        if (result == true)
                        {
                            if (!SaveEditEncounter())
                            {
                                copyEncounter = false;
                            }
                        }
                        else if (result == false)
                        {
                            CancelEditEncounter();
                        }
                        else
                        {
                            copyEncounter = false;
                        }
                    }
                    else
                    {
                        CancelEditEncounter();
                    }
                }

                if (copyEncounter)
                {
                    EncounterModel encounterModel = new EncounterModel(_selectedEncounter.EncounterModel);
                    encounterModel.Name += " (copy)";
                    encounterModel.Id    = Guid.NewGuid();

                    _compendium.AddEncounter(encounterModel);

                    if (_encounterSearchService.SearchInputApplies(_encounterSearchInput, encounterModel))
                    {
                        EncounterListItemViewModel listItem = new EncounterListItemViewModel(encounterModel);
                        _encounters.Add(listItem);
                        foreach (EncounterListItemViewModel item in _encounters)
                        {
                            item.IsSelected = false;
                        }
                        listItem.IsSelected = true;
                    }

                    _selectedEncounter = new EncounterViewModel(encounterModel);

                    SortEncounters();

                    _compendium.SaveEncounters();

                    OnPropertyChanged(nameof(SelectedEncounter));
                }
            }
        }
        public void ValidateEncounters()
        {
            var sameClaim = new Claim()
            {
                ClaimId          = 1,
                PractitionerName = "Mock Name 1",
                LocationName     = "Mock Name 1",
                SpecialtyDesc    = "Mocked SpecialtyDesc 1",
                ServiceDate      = DateTime.ParseExact("2000/07/15", "yyyy/MM/dd", CultureInfo.InvariantCulture),
                LocationAddress  = new LocationAddress()
                {
                    Province   = "BC",
                    City       = "Victoria",
                    PostalCode = "V6Y 0C2",
                    AddrLine1  = "NoWay",
                    AddrLine2  = "Alt"
                },
            };
            RequestResult <MSPVisitHistoryResponse> delegateResult = new RequestResult <MSPVisitHistoryResponse>()
            {
                ResultStatus    = Common.Constants.ResultType.Success,
                PageSize        = 100,
                PageIndex       = 1,
                ResourcePayload = new MSPVisitHistoryResponse()
                {
                    Claims = new List <Claim>()
                    {
                        sameClaim,
                        new Claim()
                        {
                            ClaimId          = 2,
                            PractitionerName = "Mock Name 2",
                            ServiceDate      = DateTime.ParseExact("2015/07/15", "yyyy/MM/dd", CultureInfo.InvariantCulture)
                        },
                        sameClaim,
                    },
                }
            };
            var expectedResult = EncounterModel.FromODRClaimModelList(delegateResult.ResourcePayload.Claims.ToList());

            string hdid      = "MOCKHDID";
            string ipAddress = "127.0.0.1";

            using Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());

            var mockMSPDelegate = new Mock <IMSPVisitDelegate>();

            mockMSPDelegate.Setup(s => s.GetMSPVisitHistoryAsync(It.IsAny <ODRHistoryQuery>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(delegateResult));

            RequestResult <PatientModel> patientResult = new RequestResult <PatientModel>()
            {
                ResultStatus    = Common.Constants.ResultType.Success,
                ResourcePayload = new PatientModel()
                {
                    PersonalHealthNumber = "912345678",
                    Birthdate            = DateTime.ParseExact("1983/07/15", "yyyy/MM/dd", CultureInfo.InvariantCulture)
                }
            };

            var mockPatientService = new Mock <IPatientService>();

            mockPatientService.Setup(s => s.GetPatient(It.IsAny <string>(), It.IsAny <PatientIdentifierType>())).Returns(Task.FromResult(patientResult));

            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();
            var context = new DefaultHttpContext()
            {
                Connection =
                {
                    RemoteIpAddress = IPAddress.Parse(ipAddress),
                },
            };

            context.Request.Headers.Add("Authorization", "MockJWTHeader");
            mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(context);


            IEncounterService service = new EncounterService(new Mock <ILogger <EncounterService> >().Object,
                                                             mockHttpContextAccessor.Object,
                                                             mockPatientService.Object,
                                                             mockMSPDelegate.Object);

            var actualResult = service.GetEncounters(hdid).Result;

            Assert.True(actualResult.ResultStatus == Common.Constants.ResultType.Success);
            Assert.Equal(2, actualResult.ResourcePayload.Count()); // should return distint claims only.
#pragma warning disable CA5351                                     // Do Not Use Broken Cryptographic Algorithms
#pragma warning disable SCS0006                                    // Weak hashing function
            using var md5CryptoService = MD5.Create();
#pragma warning restore SCS0006                                    // Weak hashing function
#pragma warning restore CA5351                                     // Do Not Use Broken Cryptographic Algorithms
            var model               = actualResult.ResourcePayload.First();
            var generatedId         = new Guid(md5CryptoService.ComputeHash(Encoding.Default.GetBytes($"{model.EncounterDate:yyyyMMdd}{model.SpecialtyDescription}{model.PractitionerName}{model.Clinic.Name}{model.Clinic.Province}{model.Clinic.City}{model.Clinic.PostalCode}{model.Clinic.AddressLine1}{model.Clinic.AddressLine2}{model.Clinic.AddressLine3}{model.Clinic.AddressLine4}")));
            var expectedGeneratedId = new Guid(md5CryptoService.ComputeHash(Encoding.Default.GetBytes($"{sameClaim.ServiceDate:yyyyMMdd}{sameClaim.SpecialtyDesc}{sameClaim.PractitionerName}{sameClaim.LocationName}{sameClaim.LocationAddress.Province}{sameClaim.LocationAddress.City}{sameClaim.LocationAddress.PostalCode}{sameClaim.LocationAddress.AddrLine1}{sameClaim.LocationAddress.AddrLine2}{sameClaim.LocationAddress.AddrLine3}{sameClaim.LocationAddress.AddrLine4}")));
            Assert.Equal(expectedGeneratedId, generatedId);
        }
        /// <summary>
        /// Creates an instance of <see cref="EncounterListItemViewModel"/>
        /// </summary>
        /// <param name="characterModel"></param>
        public EncounterListItemViewModel(EncounterModel encounterModel)
        {
            _encounterModel = encounterModel;

            Initialize();
        }
 /// <summary>
 /// Updates the model
 /// </summary>
 public void UpdateModel(EncounterModel encounterModel)
 {
     _encounterModel = encounterModel;
     Initialize();
     OnPropertyChanged(String.Empty);
 }
 private bool HasSearchText(EncounterModel encounterModel, string searchText)
 {
     return(String.IsNullOrWhiteSpace(searchText) ||
            encounterModel.Name.ToLower().Contains(searchText.ToLower()));
 }
 /// <summary>
 /// True if the search input applies to the model
 /// </summary>
 public bool SearchInputApplies(EncounterSearchInput searchInput, EncounterModel encounterModel)
 {
     return(HasSearchText(encounterModel, searchInput.SearchText));
 }
Esempio n. 13
0
        /// <summary>
        /// Creates a character archive from the character model
        /// </summary>
        public byte[] CreateEncounterArchive(EncounterModel encounterModel)
        {
            byte[] bytes = null;

            using (MemoryStream stream = new MemoryStream())
            {
                using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create))
                {
                    ZipArchiveEntry entry = archive.CreateEntry("encounter.cce");
                    using (BinaryWriter writer = new BinaryWriter(entry.Open()))
                    {
                        byte[] encounterBytes = GetEncounterBytes(encounterModel);
                        writer.Write(encounterBytes);
                    }

                    archive.CreateEntry("resources/");

                    int characterIndex = 0;
                    foreach (EncounterCharacterModel encounterCharacter in encounterModel.Creatures.Where(x => x is EncounterCharacterModel))
                    {
                        if (encounterCharacter.CharacterModel != null)
                        {
                            ZipArchiveEntry character = archive.CreateEntry($"resources/character{characterIndex++}.ccca");
                            using (BinaryWriter writer = new BinaryWriter(character.Open(), Encoding.UTF8))
                            {
                                byte[] characterArchiveBytes = CreateCharacterArchive(encounterCharacter.CharacterModel);
                                writer.Write(characterArchiveBytes);
                            }
                        }
                    }

                    ZipArchiveEntry conditions = archive.CreateEntry("resources/conditions.xml");
                    using (StreamWriter writer = new StreamWriter(conditions.Open(), Encoding.UTF8))
                    {
                        string xml = String.Empty;

                        List <Guid> ids = new List <Guid>();
                        foreach (EncounterCreatureModel encounterCreatureModel in encounterModel.Creatures)
                        {
                            foreach (AppliedConditionModel appliedConditionModel in encounterCreatureModel.Conditions)
                            {
                                if (appliedConditionModel.ConditionModel != null)
                                {
                                    if (!ids.Any(x => x == appliedConditionModel.ConditionModel.Id))
                                    {
                                        ids.Add(appliedConditionModel.ConditionModel.Id);
                                        xml += _xmlExporter.GetXML(appliedConditionModel.ConditionModel);
                                    }
                                }
                            }
                        }

                        xml = _xmlExporter.WrapAndFormatXMLWithHeader(xml);

                        writer.Write(xml);
                    }

                    ZipArchiveEntry monsters = archive.CreateEntry("resources/monsters.xml");
                    using (StreamWriter writer = new StreamWriter(monsters.Open(), Encoding.UTF8))
                    {
                        string xml = String.Empty;

                        foreach (EncounterMonsterModel encounterMonster in encounterModel.Creatures.Where(x => x is EncounterMonsterModel))
                        {
                            if (encounterMonster.MonsterModel != null)
                            {
                                List <Guid> ids = new List <Guid>();
                                if (!ids.Any(x => x == encounterMonster.MonsterModel.Id))
                                {
                                    ids.Add(encounterMonster.MonsterModel.Id);
                                    xml += _xmlExporter.GetXML(encounterMonster.MonsterModel);
                                }
                            }
                        }

                        xml = _xmlExporter.WrapAndFormatXMLWithHeader(xml);

                        writer.Write(xml);
                    }
                }

                bytes = stream.ToArray();
            }

            return(bytes);
        }
        /// <inheritdoc />
        public IEnumerable <EncounterModel> GetEncounters(byte[] encounterBytes, IEnumerable <CharacterModel> characters, IEnumerable <ConditionModel> conditions, IEnumerable <MonsterModel> monsters)
        {
            List <EncounterModel> encounters = new List <EncounterModel>();

            using (MemoryStream memoryStream = new MemoryStream(encounterBytes))
            {
                using (BinaryReader reader = new BinaryReader(memoryStream))
                {
                    int version = BitConverter.ToInt16(reader.ReadBytes(4), 0);
                    if (version == _version)
                    {
                        int encounterCount = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                        for (int i = 0; i < encounterCount; ++i)
                        {
                            EncounterModel encounter = new EncounterModel();

                            encounter.Id   = new Guid(reader.ReadBytes(16));
                            encounter.Name = ReadNextString(reader);

                            encounter.Creatures = new List <EncounterCreatureModel>();
                            int creatureCount = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            for (int j = 0; j < creatureCount; ++j)
                            {
                                bool isCharacter = BitConverter.ToBoolean(reader.ReadBytes(1), 0);

                                EncounterCreatureModel encounterCreature = isCharacter ? new EncounterCharacterModel() : new EncounterMonsterModel() as EncounterCreatureModel;
                                encounterCreature.ID                = new Guid(reader.ReadBytes(16));
                                encounterCreature.Name              = ReadNextString(reader);
                                encounterCreature.CurrentHP         = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.MaxHP             = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.AC                = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.SpellSaveDC       = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.PassivePerception = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.InitiativeBonus   = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                bool initiativeSet = BitConverter.ToBoolean(reader.ReadBytes(1), 0);
                                int? initiative    = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                encounterCreature.Initiative = initiativeSet ? initiative : null;
                                encounterCreature.Selected   = BitConverter.ToBoolean(reader.ReadBytes(1), 0);

                                encounterCreature.Conditions = new List <AppliedConditionModel>();
                                int conditionCount = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                for (int k = 0; k < conditionCount; ++k)
                                {
                                    AppliedConditionModel appliedCondition = new AppliedConditionModel();
                                    appliedCondition.ID = new Guid(reader.ReadBytes(16));

                                    Guid           conditionID    = new Guid(reader.ReadBytes(16));
                                    string         conditionName  = ReadNextString(reader);
                                    ConditionModel conditionModel = conditions.FirstOrDefault(x => x.Id == conditionID);
                                    if (conditionModel == null)
                                    {
                                        conditionModel = conditions.FirstOrDefault(x => x.Name.Equals(conditionName, StringComparison.CurrentCultureIgnoreCase));
                                    }
                                    appliedCondition.ConditionModel = conditionModel;

                                    appliedCondition.Name = ReadNextString(reader);
                                    bool hasLevel = BitConverter.ToBoolean(reader.ReadBytes(1), 0);
                                    int? level    = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                    appliedCondition.Level = hasLevel ? level : null;
                                    appliedCondition.Notes = ReadNextString(reader);

                                    encounterCreature.Conditions.Add(appliedCondition);
                                }

                                if (isCharacter)
                                {
                                    Guid           characterID   = new Guid(reader.ReadBytes(16));
                                    string         characterName = ReadNextString(reader);
                                    CharacterModel character     = characters.FirstOrDefault(x => x.Id == characterID);
                                    if (character == null)
                                    {
                                        character = characters.FirstOrDefault(x => x.Name.Equals(characterName, StringComparison.CurrentCultureIgnoreCase));
                                    }
                                    ((EncounterCharacterModel)encounterCreature).CharacterModel       = character;
                                    ((EncounterCharacterModel)encounterCreature).Level                = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                    ((EncounterCharacterModel)encounterCreature).PassiveInvestigation = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                }
                                else
                                {
                                    Guid         monsterID   = new Guid(reader.ReadBytes(16));
                                    string       monsterName = ReadNextString(reader);
                                    MonsterModel monster     = monsters.FirstOrDefault(x => x.Id == monsterID);
                                    if (monster == null)
                                    {
                                        monster = monsters.FirstOrDefault(x => x.Name.Equals(monsterName, StringComparison.CurrentCultureIgnoreCase));
                                    }
                                    ((EncounterMonsterModel)encounterCreature).MonsterModel      = monster;
                                    ((EncounterMonsterModel)encounterCreature).Quantity          = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                    ((EncounterMonsterModel)encounterCreature).AverageDamageTurn = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                                    ((EncounterMonsterModel)encounterCreature).CR = ReadNextString(reader);
                                    ((EncounterMonsterModel)encounterCreature).DamageVulnerabilities = ReadNextString(reader);
                                    ((EncounterMonsterModel)encounterCreature).DamageResistances     = ReadNextString(reader);
                                    ((EncounterMonsterModel)encounterCreature).DamageImmunities      = ReadNextString(reader);
                                    ((EncounterMonsterModel)encounterCreature).ConditionImmunities   = ReadNextString(reader);
                                }

                                encounter.Creatures.Add(encounterCreature);
                            }

                            encounter.Round = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.EncounterChallenge = (EncounterChallenge)BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.TotalCharacterHP   = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.TotalMonsterHP     = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.TimeElapsed        = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.CurrentTurn        = BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.EncounterState     = (EncounterState)BitConverter.ToInt32(reader.ReadBytes(4), 0);
                            encounter.Notes = ReadNextString(reader);

                            encounters.Add(encounter);
                        }
                    }
                }
            }

            return(encounters);
        }
Esempio n. 15
0
        public void ValidateEncounters()
        {
            RequestResult <MSPVisitHistoryResponse> delegateResult = new RequestResult <MSPVisitHistoryResponse>()
            {
                ResultStatus    = Common.Constants.ResultType.Success,
                PageSize        = 100,
                PageIndex       = 1,
                ResourcePayload = new MSPVisitHistoryResponse()
                {
                    Claims = new List <Claim>()
                    {
                        new Claim()
                        {
                            ClaimId          = 1,
                            PractitionerName = "Mock Name 1",
                            ServiceDate      = DateTime.ParseExact("2000/07/15", "yyyy/MM/dd", CultureInfo.InvariantCulture)
                        },
                        new Claim()
                        {
                            ClaimId          = 2,
                            PractitionerName = "Mock Name 2",
                            ServiceDate      = DateTime.ParseExact("2015/07/15", "yyyy/MM/dd", CultureInfo.InvariantCulture)
                        },
                    },
                }
            };
            var expectedResult = EncounterModel.FromODRClaimModelList(delegateResult.ResourcePayload.Claims.ToList());

            string hdid      = "MOCKHDID";
            string ipAddress = "127.0.0.1";

            using Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());

            var mockMSPDelegate = new Mock <IMSPVisitDelegate>();

            mockMSPDelegate.Setup(s => s.GetMSPVisitHistoryAsync(It.IsAny <ODRHistoryQuery>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(delegateResult));

            RequestResult <PatientModel> patientResult = new RequestResult <PatientModel>()
            {
                ResultStatus    = Common.Constants.ResultType.Success,
                ResourcePayload = new PatientModel()
                {
                    PersonalHealthNumber = "912345678",
                    Birthdate            = DateTime.ParseExact("1983/07/15", "yyyy/MM/dd", CultureInfo.InvariantCulture)
                }
            };

            var mockPatientService = new Mock <IPatientService>();

            mockPatientService.Setup(s => s.GetPatient(It.IsAny <string>(), It.IsAny <PatientIdentifierType>())).Returns(Task.FromResult(patientResult));

            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();
            var context = new DefaultHttpContext()
            {
                Connection =
                {
                    RemoteIpAddress = IPAddress.Parse(ipAddress),
                },
            };

            context.Request.Headers.Add("Authorization", "MockJWTHeader");
            mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(context);


            IEncounterService service = new EncounterService(new Mock <ILogger <EncounterService> >().Object,
                                                             mockHttpContextAccessor.Object,
                                                             mockPatientService.Object,
                                                             mockMSPDelegate.Object);

            var actualResult = service.GetEncounters(hdid).Result;

            Assert.True(actualResult.ResultStatus == Common.Constants.ResultType.Success &&
                        actualResult.ResourcePayload.IsDeepEqual(expectedResult));
        }