Ejemplo n.º 1
0
        public async void Update_ExistingJournal_TitleUpdated()
        {
            // Arrange
            const string userId   = "UserId";
            const string title    = "Old Title";
            const string newTitle = "New Title";

            await PrepareDatabase();

            _context.Journals.Add(new Journal {
                Id = 1L, UserId = userId, Title = title
            });
            await _context.SaveChangesAsync();

            // Act
            var service        = new JournalService(_context);
            var updatedJournal = new JournalDto
            {
                Title  = newTitle,
                UserId = userId,
                Id     = 1L
            };
            var result = await service.Update(updatedJournal);

            var updJournal = await _context.Journals.FindAsync(updatedJournal.Id);

            // Assert
            result.Title.Should().Be(updJournal.Title);
        }
        public void Can_delete_mark()
        {
            #region Arrange

            JournalMarkModel markModel;
            using (var session = DataAccess.OpenSession())
            {
                markModel = new JournalMarkModel()
                {
                    Name = "test", Value = "5.0"
                };
                session.SaveOrUpdate(markModel);
            }
            #endregion

            #region Act

            var ok = new JournalService().RemoveMark(markModel.ID);

            #endregion

            #region Assert
            Assert.IsTrue(ok);
            #endregion
        }
Ejemplo n.º 3
0
        public async void GetAll_UserFound_NoJournalLimit_Success()
        {
            // Arrange
            const string userId = "UserId";

            await PrepareDatabase();

            _context.Journals.AddRange(
                new Journal {
                Title = "One", UserId = userId
            },
                new Journal {
                Title = "Two", UserId = userId
            },
                new Journal {
                Title = "Three", UserId = userId
            }
                );
            await _context.SaveChangesAsync();

            // Act
            var service = new JournalService(_context);
            var result  = await service.GetAll(userId);

            // Assert
            result.Count.Should().Be(3);
        }
 public HomeApiController()
 {
     _newspaperService       = new NewspaperService(new DAL.LibraryContext("DbConnect"));
     _journalService         = new JournalService(new DAL.LibraryContext("DbConnect"));
     _bookService            = new BookService(new DAL.LibraryContext("DbConnect"));
     _publishingHouseService = new PublishingHouseService(new DAL.LibraryContext("DbConnect"));
 }
Ejemplo n.º 5
0
        public void Edit_WithSameName_ShouldEditJournal()
        {
            // Arrange
            StarStuffDbContext db             = this.Database;
            JournalService     journalService = new JournalService(db);

            this.SeedDatabase(db);

            const int journalId = 1;

            Journal journal = this.GetFakeJournals().FirstOrDefault(j => j.Id == journalId);

            Journal expected = new Journal
            {
                Id          = journalId,
                Name        = journal.Name,
                Description = "Not Existing",
                ImageUrl    = "Not Existing"
            };

            // Act
            journalService.Edit(journalId, expected.Name, expected.Description, expected.ImageUrl);
            Journal actual = db.Journals.Find(journalId);

            // Assert
            this.CompareJournals(expected, actual);
        }
        public ActionResult Edit(int id, JournalEdit journal)
        {
            if (!ModelState.IsValid)
            {
                return(View(journal));
            }

            if (journal.JournalId != id)
            {
                ModelState.AddModelError("", "Id mismatch.");
                return(View(journal));
            }

            var service   = new JournalService(GetGuid());
            var journalId = service.GetJournalById(id);

            if (service.UpdateJournalEntry(journal))
            {
                TempData["SaveResult"] = "Your character has been updated.";
                return(RedirectToAction("Index", "Journal", new { id = journalId.CharacterId }));
            }

            ModelState.AddModelError("", "Your character could not be updated.");
            return(View());
        }
Ejemplo n.º 7
0
        public void All_ShouldReturnValidJournals()
        {
            // Arrange
            StarStuffDbContext db             = this.Database;
            JournalService     journalService = new JournalService(db);

            this.SeedDatabase(db);

            const int page     = 2;
            const int pageSize = 5;

            List <Journal> fakeJournals = this.GetFakeJournals()
                                          .OrderBy(j => j.Name)
                                          .Skip((page - 1) * pageSize)
                                          .Take(pageSize)
                                          .ToList();

            int i = -1;

            // Act
            IEnumerable <ListJournalsServiceModel> journals = journalService.All(page, pageSize);

            // Assert
            foreach (var actual in journals)
            {
                Journal expected = fakeJournals[++i];

                this.CompareJournals(expected, actual);
            }
        }
        public string Square(SquareRootRequest petition)
        {
            logger.Debug("------- SquareRoot Method -------");

            try
            {
                if (petition == null || !(petition.Number.HasValue))
                {
                    return(Error400().ErrorMessage.ToString());
                }

                SquareRootResponse result = new SquareRootResponse();

                string key = Request.Headers.GetValues("X_Evi_Tracking_Id").FirstOrDefault();
                JournalService.Storing(Operations.Sqr(petition, result), "SquareRoot", key);

                logger.Debug(Operations.Sqr(petition, result));

                var hasonServer = JsonConvert.SerializeObject(result);
                return(hasonServer);
            }
            catch (Exception ex)
            {
                return(JsonConvert.SerializeObject(Error500(ex)));
            }
        }
        public string Multiply(MultRequest petition)
        {
            MultResponse result = new MultResponse();

            logger.Debug("------- Multiply Method -------");

            try
            {
                if (petition == null || petition.Multipliers == null)
                {
                    return(Error400().ErrorMessage.ToString());
                }

                string key = Request.Headers.GetValues("X_Evi_Tracking_Id").FirstOrDefault();
                JournalService.Storing(Operations.Mult(petition, result), "Multiplication", key);

                logger.Debug(Operations.Mult(petition, result));

                var hasonServer = JsonConvert.SerializeObject(result);
                return(hasonServer);
            }
            catch (Exception ex)
            {
                return(JsonConvert.SerializeObject(Error500(ex)));
            }
        }
Ejemplo n.º 10
0
        private JournalService CreateJournalService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new JournalService(userId);

            return(service);
        }
Ejemplo n.º 11
0
        public IActionResult UpsertJournalForUser([FromRoute] int userId, [FromRoute] int journalId, [FromBody] Journal journal)
        {
            JournalService journalService = new JournalService(Settings.GetSection("AppSettings").GetSection("DefaultConnectionString").Value);
            int            rowsAffected   = journalService.UpsertJournalForUser(userId, journalId, journal);

            return(Ok(rowsAffected));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> JournalListData(Guid id, int skip, int take)
        {
            var organizationUid = id;

            if (organizationUid.IsEmptyGuid())
            {
                organizationUid = CurrentUser.OrganizationUid;
            }

            var request = new OrganizationJournalReadListRequest(CurrentUser.Id, organizationUid);

            SetPaging(skip, take, request);

            var response = await JournalService.GetJournalsOfOrganization(request);

            if (response.Status.IsNotSuccess)
            {
                return(NotFound());
            }

            var result = new DataResult();

            result.AddHeaders("user_name", "integration_name", "message", "created_at");

            for (var i = 0; i < response.Items.Count; i++)
            {
                var item          = response.Items[i];
                var stringBuilder = new StringBuilder();
                stringBuilder.Append($"{item.Uid}{DataResult.SEPARATOR}");

                if (item.UserUid.IsNotEmptyGuid())
                {
                    stringBuilder.Append($"{result.PrepareLink($"/User/Detail/{item.UserUid}", item.UserName)}{DataResult.SEPARATOR}");
                }
                else
                {
                    stringBuilder.Append($"-{DataResult.SEPARATOR}");
                }

                if (item.IntegrationUid.IsNotEmptyGuid())
                {
                    stringBuilder.Append($"{result.PrepareLink($"/Integration/Detail/{item.IntegrationUid}", item.IntegrationName)}{DataResult.SEPARATOR}");
                }
                else
                {
                    stringBuilder.Append($"-{DataResult.SEPARATOR}");
                }

                stringBuilder.Append($"{item.Message}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{GetDateTimeAsString(item.CreatedAt)}{DataResult.SEPARATOR}");

                result.Data.Add(stringBuilder.ToString());
            }

            result.PagingInfo      = response.PagingInfo;
            result.PagingInfo.Type = PagingInfo.PAGE_NUMBERS;

            return(Json(result));
        }
        public ActionResult Details(int id)
        {
            var service = new JournalService(GetGuid(), id).GetJournalById(id);

            ViewBag.CharacterName = service.Title;

            return(View(service));
        }
Ejemplo n.º 14
0
        // GET: Journal
        public ActionResult Index()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new JournalService(userId);
            var model   = service.GetJournals();

            return(View(model));
        }
        // GET: Journal
        public ActionResult Index(int id)
        {
            var svc     = new CharacterService(GetGuid());
            var service = new JournalService(GetGuid(), id);

            ViewBag.CharacterName = svc.GetCharacterById(id).CharacterName;

            return(View(service.GetJournals()));
        }
Ejemplo n.º 16
0
        public static void CacheServerSideMetaInfo()
        {
            IJournalService     journalService = new JournalService();
            JournalMetaInputDto dto            = new JournalMetaInputDto();

            dto.GridName = "Journals Ledgers";
            var result = journalService.GetJournalsMetaData(dto);

            AppStartCache.CacheData(dto.GridName, result);
        }
Ejemplo n.º 17
0
 public JournalEntryVoucherController()
 {
     _journalService         = new JournalService();
     _groupReceiptService    = new GroupReceiptService();
     _accountHeadService     = new AccountHeadService();
     _employeeService        = new EmployeeService();
     _generalpaymentsService = new FederationGeneralPaymentsService();
     _groupService           = new GroupService();
     _clusterService         = new ClusterService();
 }
        public ActionResult DeleteJournal(int id)
        {
            var service   = new JournalService(GetGuid());
            var journalId = service.GetJournalById(id);

            service.DeleteJournalEntry(id);

            TempData["SaveResult"] = "Your journal entry was deleted.";

            return(RedirectToAction("Index", new { id = journalId.CharacterId }));
        }
Ejemplo n.º 19
0
        static void Main()
        {
            var journalService = new JournalService(true);

            journalService.Start();
            Console.WriteLine("Journal started");

            while (true)
            {
                Thread.Sleep(500);
            }
        }
Ejemplo n.º 20
0
        public IActionResult GetAllJournalsForUser([FromRoute] int userId)
        {
            JournalService journalService = new JournalService(Settings.GetSection("AppSettings").GetSection("DefaultConnectionString").Value);
            List <Journal> journalList    = journalService.GetAllJournalsForUser(userId);

            if (journalList.Count == 0)
            {
                return(NoContent());
            }

            return(Ok(journalList));
        }
 public string ClearHistory()
 {
     try
     {
         return(JournalService.ClearJournal());
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         return(JsonConvert.SerializeObject(Error500(ex)));
     }
 }
Ejemplo n.º 22
0
        public async Task CannotFindJournal()
        {
            using (var context = new AppDbContext(_options))
            {
                var service      = new JournalService(context);
                var unassignedId = 1;

                var nonExistingJournal = await service.FindById(unassignedId);

                nonExistingJournal.Should().BeNull();
            }
        }
Ejemplo n.º 23
0
        public string Div(DivRequest Reqdiv)
        {
            DivResponse response  = new DivResponse();
            string      operation = "";

            logger.Trace("----- Method Divide -----");
            try
            {
                if (Reqdiv == null || !(Reqdiv.Dividend.HasValue || Reqdiv.Divisor.HasValue))
                {
                    return(Error400().ErrorMessage.ToString());
                    //throw new ArgumentNullException();
                }
                if (Reqdiv.Divisor == 0)
                {
                    throw new DivideByZeroException();
                    //throw new Exception("The operation result is Infinite");
                }
                else
                {
                    response.Quotient  = Reqdiv.Dividend.Value / Reqdiv.Divisor.Value;
                    response.Remainder = Reqdiv.Dividend.Value % Reqdiv.Divisor.Value;
                }

                operation = $"{Reqdiv.Dividend} / {Reqdiv.Divisor}";

                logger.Trace($"{operation} = {response.Quotient}(Reaminder: {response.Remainder})");

                if (Request.Headers.GetValues("X_Evi_Tracking_Id") != null && Request.Headers.GetValues("X_Evi_Tracking_Id").Any())
                {
                    string key = Request.Headers.GetValues("X_Evi_Tracking_Id").First();

                    JournalService.StoreOperation(CreateOperation("Div", $"{operation} = {response.Quotient}(Remainder: {response.Remainder})", DateTime.Now, key));
                }

                string json = JsonConvert.SerializeObject(response);
                return(json);
            }
            catch (ArgumentNullException e)
            {
                logger.Error(e.Message);
                return(e.Message);
            }
            catch (DivideByZeroException ex)
            {
                logger.Error(ex.Message);
                return(ex.Message);
            }
            catch (Exception)
            {
                return(Error500().ErrorMessage.ToString());
            }
        }
 public string History()
 {
     try
     {
         return(JournalService.GetJournal());
     }
     catch (Exception e)
     {
         logger.Error(e.Message);
         return(e.Message);
     }
 }
Ejemplo n.º 25
0
        public void GetName_WithNotExistingId_ShouldReturnNull()
        {
            // Arrange
            StarStuffDbContext db             = this.Database;
            JournalService     journalService = new JournalService(db);

            // Act
            string result = journalService.GetName(1);

            // Assert
            Assert.Null(result);
        }
        public void CreateJournalValidationTest(string studentId, int?courseId)
        {
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(a => a.Journals.Create(It.IsAny <Journal>()));

            //Act
            var service = new JournalService(mock.Object);

            //Assert
            Assert.Throws <ValidationException>(() => service.Create(studentId, courseId));
        }
        public void DeleteCourseTest(int?id)
        {
            //Arrange
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(a => a.Journals.Get(-1)).Returns((Journal)null);

            //Act
            var service = new JournalService(mock.Object);

            //Assert
            Assert.Throws <ValidationException>(() => service.DeleteJournal(id));
        }
Ejemplo n.º 28
0
        public async Task CanCreateNewJournalSuccessfully()
        {
            using (var context = new AppDbContext(_options))
            {
                var service = new JournalService(context);
                var userId  = "User12345";
                var title   = "Test";
                var journal = await service.Create(title, userId);

                journal.Title.Should().Be(title);
                journal.UserId.Should().Be(userId);
            }
        }
Ejemplo n.º 29
0
        public async Task GetById_JournalNotFound_ThrowsJournalNotFoundException()
        {
            // Arrange
            await PrepareDatabase();

            // Act & assert
            var service = new JournalService(_context);

            service
            .Invoking(s => s.GetById(1L))
            .Should()
            .Throw <JournalNotFoundException>();
        }
Ejemplo n.º 30
0
        public void Exists_WithNotExistingName_ShouldReturnFalse()
        {
            // Arrange
            StarStuffDbContext db             = this.Database;
            JournalService     journalService = new JournalService(db);

            // Act
            string name   = this.GetFakeJournals().FirstOrDefault(j => j.Id == 1).Name;
            bool   result = journalService.Exists(name);

            // Assert
            Assert.False(result);
        }