Exemple #1
0
        public void Add_throws_db_update_exception_when_item_with_provided_term_name_already_exists()
        {
            var itemForAdd = new GlossaryItemAddDto
            {
                Term       = "Existing term",
                Definition = "Test definition"
            };

            var existingGlossaryItem = new GlossaryItem
            {
                Term       = "Existing term",
                Definition = "Test definition"
            };

            _mapperMock
            .Setup(e => e.Map <GlossaryItemAddDto, GlossaryItem>(itemForAdd))
            .Returns(existingGlossaryItem);

            _unitOfWorkMock.Setup(e => e.Commit())
            .Throws(new DbUpdateException());
            _glossaryRepositoryMock.Setup(e => e.AddAsync(existingGlossaryItem))
            .Returns(Task.CompletedTask);

            _glossaryItemsService = new GlossaryItemsService(_glossaryRepositoryMock.Object, _unitOfWorkMock.Object, _mapperMock.Object);
            Assert.ThrowsAsync <DbUpdateException>(async() => await _glossaryItemsService.AddAsync(itemForAdd));
            _unitOfWorkMock.Verify(e => e.Commit(), Times.Once);
        }
        public async Task DeleteAsync(int id)
        {
            GlossaryItem itemForRemoval = await GetItemIfExistsAsync(id);

            _glossaryRepository.Remove(itemForRemoval);
            _unitOfWork.Commit();
        }
Exemple #3
0
        public async Task <List <GlossaryItem> > GetGlossaryAsync()
        {
            var retval = new List <GlossaryItem>();

            using (var jsonStream = await StreamHelper.GetPackagedFileStreamAsync("Pages/UtilityPages/GlossaryUtility/glossary.json"))
            {
                var jsonString = await jsonStream.ReadTextAsync();

                var parsed = GlossaryJson.FromJson(jsonString);

                foreach (var category in parsed.Categories)
                {
                    foreach (var element in category.Elements)
                    {
                        var item = new GlossaryItem
                        {
                            Category    = category.Category,
                            Description = element.Description,
                            Title       = element.Title
                        };
                        retval.Add(item);
                    }
                }
            }

            return(retval);
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Term,Definition")] GlossaryItem glossary)
        {
            if (id != glossary.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    ;
                    await _glossaryService.Update(glossary);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_glossaryService.Exists(glossary.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(glossary));
        }
        public ActionResult Update(GlossaryItem items)
        {
            try
            {
                //Get the database connection
                mongoDatabase = GetMongoDatabase();
                //Build the where condition
                var filter = Builders <GlossaryItem> .Filter.Eq("Id", items.Id);

                //Build the update statement
                var updatestatement = Builders <GlossaryItem> .Update.Set("Id", items.Id);

                updatestatement = updatestatement.Set("Term", items.Term);
                updatestatement = updatestatement.Set("Definition", items.Definition);
                //fetch the details from CustomerDB based on id and pass into view
                var result = mongoDatabase.GetCollection <GlossaryItem>("GItems").UpdateOne(filter, updatestatement);
                if (result.IsAcknowledged == false)
                {
                    return(BadRequest("Unable to update Customer  " + items.Term));
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(Ok());
        }
Exemple #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //show id from 1 to 5
     if (lastId > 5)
     {
         lastId = 1;
     }
     this.item = list.Find(i => i.Id == lastId);
     lastId++;
 }
        public async Task <IActionResult> Create([Bind("Id,Term,Definition")] GlossaryItem glossary)
        {
            if (ModelState.IsValid)
            {
                await _glossaryService.Create(glossary);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(glossary));
        }
        public async Task <GlossaryItemDto> UpdateAsync(GlossaryItemUpdateDto glossaryUpdateItem, int id)
        {
            GlossaryItem itemForUpdate = await GetItemIfExistsAsync(id);

            itemForUpdate.Definition = glossaryUpdateItem.Definition;
            _unitOfWork.Commit();

            var glossaryItemResultDto = _mapper.Map <GlossaryItem, GlossaryItemDto>(itemForUpdate);

            return(glossaryItemResultDto);
        }
Exemple #9
0
        public ActionResult <GlossaryItem> Get(string term)
        {
            GlossaryItem glossaryItem = Glossary.Find(item => item.Term.Equals(term, StringComparison.InvariantCultureIgnoreCase));

            if (glossaryItem == null)
            {
                return(NotFound());
            }

            return(Ok(glossaryItem));
        }
Exemple #10
0
        public Task <int> InsertGlossaryItem(GlossaryItem item)
        {
            string sql = @$ "INSERT INTO glossary (term, definition)
                        SELECT @Term, @Definition
                        WHERE
                        NOT EXISTS (
                        SELECT term FROM glossary WHERE term = @Term
                        );";

            return(_db.SaveData(sql, item));
        }
Exemple #11
0
 private void InitFakes()
 {
     Fake1 = new GlossaryItem {
         Id = Guid.NewGuid(), Term = "Fake1", Definition = "A Fake glossary Item Number 1"
     };
     Fake2 = new GlossaryItem {
         Id = Guid.NewGuid(), Term = "Fake2", Definition = "A Fake glossary Item Number 2"
     };
     Fake3 = new GlossaryItem {
         Id = Guid.NewGuid(), Term = "Fake3", Definition = "A Fake glossary Item Number 3"
     };
 }
        public void RemoveGlossaryItem_ExpectNoExceptions()
        {
            Glossary     glossary = new Glossary();
            GlossaryItem gi       = new GlossaryItem("Happy Octopus", "HO", false);

            glossary.AddGlossaryItem(gi);
            glossary.AddGlossaryItem(new GlossaryItem("Happy Otters", "HO", false));
            glossary.AddGlossaryItem(new GlossaryItem("Hearing Office", "HO", true));
            Assert.Equal(3, glossary.GlossaryItems.Count);
            glossary.RemoveGlossaryItem(gi);
            Assert.Equal(2, glossary.GlossaryItems.Count);
        }
Exemple #13
0
    public BaseUnit GetPrefabUnit(PaintType paint)
    {
        GlossaryItem glossary = GetGlossaryItem(paint);

        foreach (var typ in unitTyps)
        {
            if (typ.unitType == glossary.unitType)
            {
                return(typ.baseUnit);
            }
        }
        return(null);
    }
Exemple #14
0
    public BaseTile GetPrefabTile(PaintType paint)
    {
        GlossaryItem glossary = GetGlossaryItem(paint);

        foreach (var typ in tileTypes)
        {
            if (typ.tileType == glossary.tileType)
            {
                return(typ.baseTile);
            }
        }
        return(null);
    }
Exemple #15
0
    public BaseObject GetPrefabObject(PaintType paint)
    {
        GlossaryItem glossary = GetGlossaryItem(paint);

        foreach (var typ in objectTypes)
        {
            if (typ.objectType == glossary.objectType)
            {
                return(typ.baseObject);
            }
        }
        return(null);
    }
Exemple #16
0
        public Boolean SaveOrUpdateItem(Domain.Dto.AddEditItemDto ItemDTO)
        {
            Int64         OldGroupId = ItemDTO.GroupId;
            Boolean       isOk       = false;
            GlossaryItem  Item;
            GlossaryGroup Group = Manager.Get <GlossaryGroup>(ItemDTO.GroupId);

            Person user = Manager.Get <Person>(UC.CurrentUserID);


            if (ItemDTO.Id > 0)
            {
                Item       = Manager.Get <GlossaryItem>(ItemDTO.Id);
                OldGroupId = Item.Group.Id;

                Item.UpdateMetaInfo(user, UC.IpAddress, UC.ProxyIpAddress);
            }
            else
            {
                Item = new GlossaryItem();
                Item.CreateMetaInfo(user, UC.IpAddress, UC.ProxyIpAddress);
            }

            Item.Group      = Group;
            Item.Term       = ItemDTO.Term;
            Item.Definition = ItemDTO.Definition;
            Item.SetFirstLetter();

            try
            {
                Manager.SaveOrUpdate <GlossaryItem>(Item);
                isOk = true;
            }
            catch (Exception ex)
            {
            }



            if (isOk)
            {
                UpdateGlossaryItemNumber(ItemDTO.GroupId, true);
                if (OldGroupId != ItemDTO.GroupId)
                {
                    UpdateGlossaryItemNumber(OldGroupId, false);
                }
            }

            return(isOk);
        }
        public ActionResult Put(GlossaryItem glossaryItem)
        {
            var existingGlossaryItem = Glossary.Find(item => item.Term.Equals(glossaryItem.Term, StringComparison.InvariantCultureIgnoreCase));

            if (existingGlossaryItem == null)
            {
                return(BadRequest("Cannot update a non existing term."));
            }
            else
            {
                existingGlossaryItem.Definition = glossaryItem.Definition;
                return(Ok());
            }
        }
        public async Task <ActionResult> Post(GlossaryItem glossaryItem)
        {
            var rowsChanged = await _db.InsertGlossaryItem(glossaryItem);

            if (rowsChanged == 0)
            {
                return(Conflict("Cannot create the term because it already exists."));
            }
            else
            {
                var resourceUrl = Path.Combine(Request.Path.ToString(), Uri.EscapeUriString(glossaryItem.Term));
                return(Created(resourceUrl, glossaryItem));
            }
        }
Exemple #19
0
        public void Delete_throws_non_existing_item_exception_when_item_not_found()
        {
            GlossaryItem glossaryItemNull = null;

            _glossaryRepositoryMock.Setup(e => e.FindByIdAsync(3))
            .Returns(Task.FromResult(glossaryItemNull));
            _unitOfWorkMock.Setup(e => e.Commit());

            _glossaryItemsService = new GlossaryItemsService(_glossaryRepositoryMock.Object, _unitOfWorkMock.Object, _mapperMock.Object);

            Assert.ThrowsAsync <NonExistingItemException>(() => _glossaryItemsService.DeleteAsync(3));
            _glossaryRepositoryMock.Verify(e => e.FindByIdAsync(3), Times.Once);
            _unitOfWorkMock.Verify(e => e.Commit(), Times.Never);
        }
Exemple #20
0
 public ActionResult Delete(int id, IFormCollection collection)
 {
     try
     {
         // TODO: Add delete logic here
         GlossaryItem item = new GlossaryItem();
         item.Id = id;
         _repos.Delete(item);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
        private void EditGlossaryItem(GlossaryItem entry)
        {
            newGlossaryItem = new GlossaryItem {
                Term       = entry.Term,
                Definition = entry.Definition
            };

            Type = "Edit";

            TermInputIsReadonly = true;

            Visibility = true;

            StateHasChanged();
        }
Exemple #22
0
        public ActionResult Post(GlossaryItem glossaryItem)
        {
            var existingGlossaryItem = Glossary.Find(item =>
                                                     item.Term.Equals(glossaryItem.Term, StringComparison.InvariantCultureIgnoreCase));

            if (existingGlossaryItem != null)
            {
                return(Conflict("Cannot create the term because it already exists."));
            }
            else
            {
                Glossary.Add(glossaryItem);
                return(CreatedAtAction(nameof(Get), new { term = glossaryItem.Term }, glossaryItem));
            }
        }
        public ActionResult Delete(GlossaryItem glossaryItem)
        {
            var existingGlossaryItem = Glossary.Find(item =>
                                                     item.Term.Equals(glossaryItem.Term, StringComparison.InvariantCultureIgnoreCase));

            if (existingGlossaryItem == null)
            {
                return(NotFound());
            }
            else
            {
                Glossary.Remove(glossaryItem);
                return(NoContent());
            }
        }
        public ActionResult Post(GlossaryItem glossaryItem)
        {
            try
            {
                //Get the database connection
                mongoDatabase = GetMongoDatabase();
                mongoDatabase.GetCollection <GlossaryItem>("GItems").InsertOne(glossaryItem);
            }
            catch (Exception)
            {
                throw;
            }
            var resourceUrl = Path.Combine(Request.Path.ToString(), Uri.EscapeUriString(glossaryItem.Term));

            return(Created(resourceUrl, glossaryItem));
        }
Exemple #25
0
 public ActionResult Create(IFormCollection collection)
 {
     try
     {
         // TODO: Add insert logic here
         GlossaryItem item = new GlossaryItem();
         item.Term       = collection["Term"];
         item.Definition = collection["Definition"];
         _repos.Create(item);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Exemple #26
0
        public ActionResult Post(GlossaryItem glossaryItem)
        {
            var existingGlossaryItem = Glossary.Find(item =>
                                                     item.Term.Equals(glossaryItem.Term, StringComparison.InvariantCultureIgnoreCase));

            if (existingGlossaryItem != null)
            {
                return(Conflict("Cannot create the term because it already exist"));
            }
            else
            {
                Glossary.Add(glossaryItem);
                var resourceUrl = Path.Combine(Request.Path.ToString(), Uri.EscapeUriString(glossaryItem.Term));
                return(Created(resourceUrl, glossaryItem));
            }
        }
        public ActionResult <GlossaryItem> Get(string term)
        {
            if (term == null)
            {
                return(NotFound());
            }

            mongoDatabase = GetMongoDatabase();
            GlossaryItem customer = mongoDatabase.GetCollection <GlossaryItem>("GItems").Find <GlossaryItem>
                                        (k => k.Term == term).FirstOrDefault();

            if (customer == null)
            {
                return(NotFound());
            }
            return(customer);
        }
Exemple #28
0
 public ActionResult Edit(int id, IFormCollection collection)
 {
     try
     {
         // TODO: Add update logic here
         GlossaryItem item = new GlossaryItem();
         item.Id         = id;
         item.Term       = collection["Term"];
         item.Definition = collection["Definition"];
         _repos.Update(item);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Exemple #29
0
        Embed CreateEmbed(GlossaryItem item)
        {
            var embed = new EmbedBuilder()
            {
                Color       = new Color(147, 196, 211),
                Title       = item.Term,
                Url         = $"https://wazeopedia.waze.com/wiki/USA/Glossary#{item.Ids[0]}",
                Description = item.Description,

                Footer = new EmbedFooterBuilder
                {
                    Text = $"Last updated on {item.ModifiedAt.Date.ToString("yyyy-MM-dd")}"
                }
            };

            return(embed.Build());
        }
        public void ChangeGlossaryitem_ExpectException()
        {
            GlossaryItem gi = new GlossaryItem();

            gi.Abbreviation = "test";
            gi.Term         = "term";
            bool threwException = false;

            try
            {
                gi.Abbreviation = "changed";
            }
            catch (Exception)
            {
                threwException = true;
            }
            Assert.True(threwException);
        }
Exemple #31
0
    public List<GlossaryItem> SearchGlossary(String SearchString, String Language)
    {
        List<GlossaryItem> GlossaryItems = new List<GlossaryItem>();
           SqlConnection con = new SqlConnection(
           WebConfigurationManager.ConnectionStrings["iLearnConnectionString"].ConnectionString);

           String sql = "EXEC [dbo].[SearchGlossaryItems]";
           sql += "@SearchString = N'{0}',";
           sql += "@Language = N'{1}'";
           sql = String.Format(sql, SearchString, Language);

           SqlCommand cmd = new SqlCommand(sql, con);
           try
           {
          con.Open();
          SqlDataReader reader = cmd.ExecuteReader();
          while (reader.Read())
          {
             GlossaryItem glossaryInfo = new GlossaryItem(reader["word"].ToString(), reader["tlword"].ToString());
             GlossaryItems.Add(glossaryInfo);
          }
           }
           catch (SqlException err)
           {
           }
           finally
           {
          con.Close();
           }
           return GlossaryItems;
    }
Exemple #32
0
    public List<GlossaryItem> GetGlossaryItemDetails(String GlossaryIndex, String Language)
    {
        List<GlossaryItem> GlossaryItems = new List<GlossaryItem>();

           SqlConnection con = new SqlConnection(
           WebConfigurationManager.ConnectionStrings["iLearnConnectionString"].ConnectionString);

           String sql = "EXEC [dbo].[GetGlossaryItemDetails]";
           sql += "@GlossaryWord = N'{0}',";
           sql += "@Language = N'{1}'";
           sql = String.Format(sql, GlossaryIndex, Language);

           SqlCommand cmd = new SqlCommand(sql, con);
           try
           {
          con.Open();
          SqlDataReader reader = cmd.ExecuteReader();
          while (reader.Read())
          {
             GlossaryItem glossaryInfo   = new GlossaryItem(reader["word"].ToString(), reader["tlWord"].ToString());
             glossaryInfo.Context	    = reader["context"].ToString();
             glossaryInfo.Lesson	    = Convert.ToInt32(reader["lessonID"]);
             glossaryInfo.Activity	    = Convert.ToInt32(reader["activityID"]);
             GlossaryItems.Add(glossaryInfo);
          }
           }
           catch (SqlException err)
           {
           }
           finally
           {
          con.Close();
           }
           return GlossaryItems;
    }