public void GetUnit()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit. ID provided is 0, which will indicates creation of new helpdesk.
            TestDataUnit unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID);

            Topic topic = new Topic()
            {
                Name      = AlphaNumericStringGenerator.GetString(10),
                IsDeleted = false,
                UnitId    = unitData.Response.UnitID
            };
            Topic deletedTopic = new Topic()
            {
                Name      = AlphaNumericStringGenerator.GetString(10),
                IsDeleted = true,
                UnitId    = unitData.Response.UnitID
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Topic.Add(topic);
                context.Topic.Add(deletedTopic);
                context.SaveChanges();
            }

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            // Get the unit that was just created.
            UnitsFacade     unitsFacade     = new UnitsFacade();
            GetUnitResponse getUnitResponse = unitsFacade.GetUnit(unitData.Response.UnitID);

            // Check that unit response is okay and that names match.
            Assert.AreEqual(HttpStatusCode.OK, getUnitResponse.Status);
            Assert.AreEqual(unitData.Request.Name, getUnitResponse.Unit.Name);
            Assert.IsTrue(getUnitResponse.Unit.Topics.Count == 2);
            Assert.AreEqual(topic.Name, getUnitResponse.Unit.Topics[1].Name);
        }
Exemple #2
0
        public async Task <GetUnitResponse> GetUnit()
        {
            await MasterDataLoader.LoadAsync();

            var masterData = MasterDataLoader.LatestMasterData;

            if (masterData == null)
            {
                // todo: error message
                throw new Exception("master data not exist");
            }

            var mobileSuitIds = masterData.AllMobileSuitIds.OrderBy(x => x);
            var dictionary    = _translationService.GetMobileSuitDictionary();

            var temporarilyDisabledItems = await Common2DB.DisabledMobileSuits.ToListAsync();

            var response = new GetUnitResponse();

            response.units = new List <GetUnitResponse.Unit>();

            foreach (var mobileSuitId in mobileSuitIds)
            {
                var mobileSuit = masterData.GetMobileSuit(mobileSuitId);

                if (mobileSuit == null)
                {
                    continue;
                }

                TranslationItemCommon translationItem;
                dictionary.TryGetValue(mobileSuitId, out translationItem);

                var isEnabledInGmTool = !temporarilyDisabledItems.Any(x => x.itemId == mobileSuit.itemId);

                response.units.Add(new GetUnitResponse.Unit
                {
                    mobileSuitId          = mobileSuitId,
                    displayNameJapanese   = translationItem?.JpText ?? mobileSuitId,
                    displayNameEnglish    = translationItem?.EnText ?? mobileSuitId,
                    isEnabledOnMasterData = mobileSuit.availabled,
                    isEnabledOnGmTool     = isEnabledInGmTool,
                    isAvailable           = mobileSuit.availabled && isEnabledInGmTool,
                });
            }

            return(response);
        }
        public void DeleteUnit()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit. ID provided is 0, which will indicates creation of new helpdesk.
            List <string> topics   = new List <string>(new string[] { "Layouts", "Lifecycle" });
            TestDataUnit  unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID, "", "", false, topics);

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            // Test get, delete, get.
            UnitsFacade unitsFacade = new UnitsFacade();

            // Get the unit that was just created.
            GetUnitResponse getUnitResponse = unitsFacade.GetUnit(unitData.Response.UnitID);

            Assert.AreEqual(HttpStatusCode.OK, getUnitResponse.Status);

            // Delete the unit that was just created.
            DeleteUnitResponse deleteUnitResponse = unitsFacade.DeleteUnit(unitData.Response.UnitID);

            Assert.AreEqual(HttpStatusCode.OK, deleteUnitResponse.Status);

            // Try getting the unit that was just deleted. Should be NotFound.
            //Will update unit test when get unit method is implemented that excludes units
            //with IsDeleted = true
            getUnitResponse = unitsFacade.GetUnit(unitData.Response.UnitID);
            Assert.IsTrue(getUnitResponse.Unit.IsDeleted);
        }