public async Task WhenAdd_NumberOfRecordsShouldIncrease() { //arange var options = new DbContextOptionsBuilder <GravityGymDbContext>() .UseInMemoryDatabase(databaseName: "Add_UsefulLinks") .Options; using (var ctx = new GravityGymDbContext(options)) { ctx.UsefulLinks.AddRange(_usefulLinks); ctx.SaveChanges(); } using (var ctx = new GravityGymDbContext(options)) { var usefulLinkRepo = new UsefulLinksRepository(ctx, _mapperMoq.Object); var ul = new UsefulLink { Id = 5L, Description = "some description 5", Link = "https://amdaris.com/" }; //act await usefulLinkRepo.AddAsync(ul); var result = await usefulLinkRepo.GetAllAsync(); //assert Assert.Greater(result.Count, _usefulLinks.Count); } }
public async Task WhenGetAll_ShouldReturnListOfUsefulLink() { //arange var options = new DbContextOptionsBuilder <GravityGymDbContext>() .UseInMemoryDatabase(databaseName: "Get_UsefulLinks") .Options; using (var ctx = new GravityGymDbContext(options)) { ctx.UsefulLinks.AddRange(_usefulLinks); ctx.SaveChanges(); } using (var ctx = new GravityGymDbContext(options)) { var usefulLinkRepo = new UsefulLinksRepository(ctx, _mapperMoq.Object); //act var result = await usefulLinkRepo.GetAllAsync(); //assert Assert.IsInstanceOf(typeof(IList <UsefulLink>), result); } }
public async Task WhenGetById_ShouldReturnSpecificUsefulLink() { //arange var options = new DbContextOptionsBuilder <GravityGymDbContext>() .UseInMemoryDatabase(databaseName: "GetWithId_UsefulLinks") .Options; using (var ctx = new GravityGymDbContext(options)) { ctx.UsefulLinks.AddRange(_usefulLinks); ctx.SaveChanges(); } using (var ctx = new GravityGymDbContext(options)) { var usefulLinkRepo = new UsefulLinksRepository(ctx, _mapperMoq.Object); //act var result = await usefulLinkRepo.GetByIdAsync(2L); //assert var actual = _usefulLinks.Where(ul => ul.Id == 2L).FirstOrDefault(); Assert.AreEqual(result.Id, actual.Id); Assert.AreEqual(result.Link, actual.Link); Assert.AreEqual(result.Description, actual.Description); } }
public async Task WhenDelete_NumberOfRecordsShouldDecrease() { //arange var options = new DbContextOptionsBuilder <GravityGymDbContext>() .UseInMemoryDatabase(databaseName: "Delete_UsefulLinks") .Options; using (var ctx = new GravityGymDbContext(options)) { ctx.UsefulLinks.AddRange(_usefulLinks); ctx.SaveChanges(); } using (var ctx = new GravityGymDbContext(options)) { var usefulLinkRepo = new UsefulLinksRepository(ctx, _mapperMoq.Object); //act await usefulLinkRepo.DeleteAsync(_usefulLinks[2]); await usefulLinkRepo.DeleteAsync(2); var result = await usefulLinkRepo.GetAllAsync(); //assert Assert.Less(result.Count, _usefulLinks.Count); } }
private string AddUsefulLinks() { JavaScriptSerializer jss = new JavaScriptSerializer(); var paramDes = jss.Deserialize <IEnumerable <AppUsefulLinks> >(Request["queryParam"]); using (MainDBUnitWorkContext context = new MainDBUnitWorkContext()) { IUsefulLinksRepository _linkRepo = new UsefulLinksRepository(context); UsefulLinksService manager = new UsefulLinksService(_linkRepo); return(jss.Serialize(manager.Update(paramDes, int.Parse(Request["linkType"])))); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["IsAuthorized"] == null) { // No login account Response.Redirect("../MyAccounts/NoLoginPage.aspx"); return; } HiddenField1.Value = Page.User.Identity.Name; Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache); string userName = Page.User.Identity.Name; using (MainDBUnitWorkContext context = new MainDBUnitWorkContext()) { UserService manager = new UserService(context); var user_temp = manager.GetUserByLoginName(userName); //if (user_temp.Sex == true) //{ // owner_image_id.ImageUrl = (user_temp.HeadPhoto == null) ? "../Images/men.jpg" : user_temp.HeadPhoto; //} //else //{ // owner_image_id.ImageUrl = (user_temp.HeadPhoto == null) ? "../Images/women.jpg" : user_temp.HeadPhoto; //} owner_name_id.Text = user_temp.UserName; owner_name_id.NavigateUrl = ""; // Get report links IUsefulLinksRepository repository = new UsefulLinksRepository(); UsefulLinksService _manager = new UsefulLinksService(repository); var usefulLinks = _manager.GetAllUsefulLinks(UsefulLinksTypeEnum.ParentOnly); linksRept.DataSource = usefulLinks.ToList <AppUsefulLinks>(); linksRept.DataBind(); } }
private string GetUsefulLinks(string parentOnly) { JavaScriptSerializer jss = new JavaScriptSerializer(); using (MainDBUnitWorkContext context = new MainDBUnitWorkContext()) { IUsefulLinksRepository repository = new UsefulLinksRepository(context); UsefulLinksService manager = new UsefulLinksService(repository); if (parentOnly == "1") { return(jss.Serialize(manager.GetAllUsefulLinks(UsefulLinksTypeEnum.ParentOnly))); } else if (parentOnly == "0") { return(jss.Serialize(manager.GetAllUsefulLinks(UsefulLinksTypeEnum.ChildOnly))); } else { throw new ArgumentException("Could only get parent or child categories by this method"); } } }
public async Task WhenUpdateUL_ShouldBeUpdated() { //arange var options = new DbContextOptionsBuilder <GravityGymDbContext>() .UseInMemoryDatabase(databaseName: "UpdateWithId_UsefulLinks") .Options; using (var ctx = new GravityGymDbContext(options)) { ctx.UsefulLinks.AddRange(_usefulLinks); ctx.SaveChanges(); } using (var ctx = new GravityGymDbContext(options)) { var usefulLinkRepo = new UsefulLinksRepository(ctx, _mapperMoq.Object); //act var ul = await usefulLinkRepo.GetByIdAsync(2L); ul.Description = "NUnit Test"; ul.Link = "https://amdariss.com/"; await usefulLinkRepo.UpdateAsync(ul); var result = await usefulLinkRepo.GetByIdAsync(2L); //assert Assert.AreEqual(result.Id, ul.Id); Assert.AreEqual(result.Link, ul.Link); Assert.AreEqual(result.Description, ul.Description); } }