Ejemplo n.º 1
0
        public void TestInsertAndUpdateByUid()
        {
            JournalProxy proxy  = new JournalProxy();
            JournalDto   insert = CreateJournalDto();

            proxy.Insert(insert);

            Assert.IsTrue(insert.Uid > 0, "Uid must be > 0 after save.");

            JournalDto read = (JournalDto)proxy.GetByUid(insert.Uid);

            read.Notes = "Updated";

            // change Total and Flip Them Around
            read.Items[0].Amount = 345.78M;
            read.Items[0].Type   = DebitCreditType.Debit;

            read.Items[1].Amount = 345.78M;
            read.Items[1].Type   = DebitCreditType.Credit;

            proxy.Update(read);

            JournalDto updated = (JournalDto)proxy.GetByUid(insert.Uid);

            ReflectionTester.AssertAreEqual("Journal", read, updated);
        }
Ejemplo n.º 2
0
        private JournalDto CreateJournalDto()
        {
            JournalDto dto = new JournalDto();

            dto.Date             = DateTime.UtcNow.Date;
            dto.Notes            = "Notes";
            dto.RequiresFollowUp = false;
            dto.Reference        = "#12345";
            dto.Summary          = "Summary";
            dto.Tags             = "ABC, DEF";
            dto.FCToBCFXRate     = 1M;

            JournalItemDto row1 = new JournalItemDto();

            row1.AccountUid = this.ExpenseOffice.Uid;
            row1.TaxCode    = TaxCode.ExpInclGst;
            row1.Type       = DebitCreditType.Credit;
            row1.Amount     = 123.45M;

            JournalItemDto row2 = new JournalItemDto();

            row2.AccountUid = this.ExpenseTelco.Uid;
            row2.TaxCode    = TaxCode.ExpInclGst;
            row2.Type       = DebitCreditType.Debit;
            row2.Amount     = 123.45M;

            dto.Items = new JournalItemDto[]
            {
                row1, row2
            };

            return(dto);
        }
Ejemplo n.º 3
0
        public ActionResult <JournalDto> GetJournal(string socialSecurityNumber)
        {
            var foundJournal = Journals
                               .FirstOrDefault(x => x.SocialSecurityNumber == socialSecurityNumber);

            if (foundJournal is null)
            {
                return(NotFound()); // 404 Not Found
            }

            var dto = new JournalDto
            {
                Id = foundJournal.Id,
                SocialSecurityNumber = foundJournal.SocialSecurityNumber,
                Entries = foundJournal.Entries.Select(x => new JournalEntryDto
                {
                    Id      = x.Id,
                    Date    = x.Date,
                    EntryBy = x.EntryBy,
                    Entry   = x.Entry
                })
            };

            return(dto);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        private JournalDto CreateJournalDto2()
        {
            JournalDto dto = new JournalDto();

            dto.Date               = DateTime.UtcNow.Date;
            dto.Summary            = "Summary";
            dto.Tags               = "Journal, MultiCcy";
            dto.AutoPopulateFXRate = true;
            dto.Ccy = "USD";

            JournalItemDto row1 = new JournalItemDto();

            row1.AccountUid = this.IncomeSubscription.Uid;
            row1.TaxCode    = TaxCode.SaleInclGst;
            row1.Type       = DebitCreditType.Credit;
            row1.Amount     = 100M;

            JournalItemDto row2 = new JournalItemDto();

            row2.AccountUid = this.IncomeShipping.Uid;
            row2.TaxCode    = TaxCode.SaleInclGst;
            row2.Type       = DebitCreditType.Credit;
            row2.Amount     = 50M;

            JournalItemDto row3 = new JournalItemDto();

            row3.AccountUid = this.Westpac.Uid;
            row3.Type       = DebitCreditType.Debit;
            row3.Amount     = 150M;

            dto.Items = new JournalItemDto[] { row1, row2, row3 };

            return(dto);
        }
        public ActionResult JournalDisplay(string journalId)
        {
            var curUrl = ConfigurationManager.AppSettings["url"];

            curUrl = curUrl.TrimEnd('/');

            PlantDAL.EDMX.Journal journal = JournalCRUD.GetByID(Guid.Parse(journalId));
            JournalDto            dto     = Mappers.JournalMapper.MapDALToDto(journal);

            List <Images> imgs = ImageCRUD.GetByJournalID(Guid.Parse(journalId));

            foreach (var img in imgs)
            {
                var idx = img.ImageFilePath.ToLower().IndexOf(@"\images\");
                if (dto.imageFilePath == null)
                {
                    dto.imageFilePath = new List <string>();
                }
                if (idx != -1)
                {
                    var imgpath = curUrl + img.ImageFilePath.Substring(idx).Replace("\\", "/");
                    dto.imageFilePath.Add(imgpath);
                }
            }

            PlantDAL.EDMX.Plant plant = PlantCRUD.GetByID(dto.PlantId);

            dto.Plants.Add(new SelectListItem
            {
                Text  = plant.Name,
                Value = plant.ID.ToString()
            });

            return(View(dto));
        }
Ejemplo n.º 7
0
        public void FindJournalsByLastModifiedDate()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto   first = CreateJournalDto();

            first.Date = DateTime.Parse("01-Jan-2010");
            Thread.Sleep(5 * 1000);
            proxy.Insert(first);

            DateTime firstInsert = first.UtcLastModified;

            Thread.Sleep(10 * 1000);

            JournalDto second = CreateJournalDto();

            second.Date = DateTime.Parse("01-Jan-2010");
            Thread.Sleep(5 * 1000);
            proxy.Insert(second);

            DateTime secondInsert = second.UtcLastModified.AddSeconds(-1);

            List <JournalDto> secondOnly = proxy.FindList <JournalDto>(JournalProxy.ResponseXPath, "UtcLastModifiedFrom", secondInsert.ToString("s"), "UtcLastModifiedTo", DateTime.UtcNow.AddMinutes(5).ToString("s"));

            Assert.AreEqual(1, secondOnly.Count);
            // ReflectionTester.AssertAreEqual(second, secondOnly[0], "UtcLastModified");

            List <JournalDto> firstAndSecond = proxy.FindList <JournalDto>(JournalProxy.ResponseXPath, "UtcLastModifiedFrom", firstInsert.ToString("s"), "UtcLastModifiedTo", DateTime.UtcNow.AddMinutes(5).ToString("s"));

            Assert.AreEqual(2, firstAndSecond.Count);
            //ReflectionTester.AssertAreEqual(first, firstAndSecond[0], "UtcLastModified");
            //ReflectionTester.AssertAreEqual(second, firstAndSecond[1], "UtcLastModified");
        }
Ejemplo n.º 8
0
        public async void AddJournal(int interventionId, JournalDto journalDto)
        {
            var newJournal = _mapper.Map <Journal>(journalDto);

            newJournal.InterventionId = interventionId;
            _journalService.Add(newJournal);
            await _interventionHub.Clients.All.SendAsync("journalUpdated", interventionId, newJournal.Id);
        }
        public void UpdateJournal(JournalDto journal)
        {
            var dbJournal = Database.Journals.Get(journal.Id);

            dbJournal.Mark = journal.Mark;

            Database.Journals.Update(dbJournal);
        }
Ejemplo n.º 10
0
        public void InvalidAccountAndTaxCodeCombination()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto   dto   = CreateJournalDto();

            dto.Items[0].AccountUid = StGeorge.Uid;
            dto.Items[0].TaxCode    = TaxCode.SaleInclGst;

            proxy.Insert(dto);
        }
Ejemplo n.º 11
0
        public void TestInsertAndGetByUid()
        {
            JournalProxy proxy  = new JournalProxy();
            JournalDto   insert = CreateJournalDto();

            proxy.Insert(insert);

            Assert.IsTrue(insert.Uid > 0, "Uid must be > 0 after save.");

            JournalDto read = (JournalDto)proxy.GetByUid(insert.Uid);

            ReflectionTester.AssertAreEqual("Journal", insert, read, new[] { "Tags" });
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> Update(long journalId, [FromBody] JournalDto journal)
        {
            var result = await _service.Update(journal);

            if (result == null)
            {
                _logger.LogInformation("Unable to retrieve and update journal");
                return(BadRequest());
            }

            _logger.LogInformation($"Updated journal: {journalId}");
            return(Ok(result));
        }
Ejemplo n.º 13
0
        public async void Update_JournalNotFound_NotUpdated()
        {
            // Arrange
            await PrepareDatabase();

            var service = new JournalService(_context);
            var journal = new JournalDto {
                Id = 1L
            };

            // Act & assert
            service.Invoking(s => s.Update(journal))
            .Should()
            .Throw <JournalNotFoundException>();
        }
Ejemplo n.º 14
0
        public static JournalDto MapDALToDto(Journal journal)
        {
            JournalDto dto = new JournalDto();

            dto.UserID = journal.UserID;
            dto.ID     = journal.ID;
            dto.Name   = journal.Name;
            dto.Notes  = journal.Notes;
            if (journal.PlantID != null)
            {
                dto.PlantId = journal.PlantID ?? Guid.Empty;
            }


            return(dto);
        }
Ejemplo n.º 15
0
        public static Journal MapDtoToDAL(JournalDto journalDto, List <Images> imgList)
        {
            Journal journal = new Journal();

            journal.UserID = journalDto.UserID;
            journal.ID     = journalDto.ID;
            journal.Name   = journalDto.Name;
            journal.Notes  = journalDto.Notes;
            journal.Images = imgList;
            if (journalDto.PlantId != null)
            {
                journal.PlantID = journalDto.PlantId;
            }

            return(journal);
        }
Ejemplo n.º 16
0
        public void TestInsertAndGetByUidUnbalanced()
        {
            JournalProxy proxy  = new JournalProxy();
            JournalDto   insert = CreateJournalDto();

            insert.Items[0].Amount = 1999;
            try
            {
                proxy.Insert(insert);
                Assert.Fail("No error was thrown.");
            }
            catch (RestException ex)
            {
                Assert.AreEqual("The debit and credit total for the transaction items in this transaction do not match. Out of balance: -1,875.55.", ex.Message, "Incorrect error message.");
            }
        }
Ejemplo n.º 17
0
        public ActionResult NewJournal(JournalDto journalDto)
        {
            Guid id = Guid.NewGuid();

            journalDto.ID     = id;
            journalDto.UserID = User.Identity.GetUserId();

            var           plantDir = Server.MapPath("~/Images/Journal/" + id.ToString());
            List <Images> imgList  = Mappers.ImageMapper.MapHTTPToImage(journalDto.Images, journalDto, plantDir);

            PlantDAL.EDMX.Journal journal = Mappers.JournalMapper.MapDtoToDAL(journalDto, imgList);
            journal.DateModified = DateTime.Now;

            JournalCRUD.Insert(journal);
            return(RedirectToAction("JournalTable"));
        }
Ejemplo n.º 18
0
        public ActionResult JournalDetails(JournalDto journalDto)
        {
            var           plantDir = Server.MapPath("~/Images/Journal/" + journalDto.ID.ToString());
            List <Images> imgList  = Mappers.ImageMapper.MapHTTPToImage(journalDto.Images, journalDto, plantDir);

            foreach (var img in imgList)
            {
                ImageCRUD.Insert(img);
            }

            PlantDAL.EDMX.Journal journal = Mappers.JournalMapper.MapDtoToDAL(journalDto, imgList);
            journal.UserID = User.Identity.GetUserId();

            JournalCRUD.Update(journal);

            return(RedirectToAction("JournalTable"));
        }
Ejemplo n.º 19
0
        public void Update()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto   dto   = CreateJournalDto();

            proxy.Insert(dto);

            Assert.IsTrue(dto.Uid > 0, "Uid must be > 0 after save.");

            dto.Summary = "Add some summary.";
            dto.Notes   = "Updated journal.";
            proxy.Update(dto);

            JournalDto read = (JournalDto)proxy.GetByUid(dto.Uid);

            ReflectionTester.AssertAreEqual("Journal", dto, read, new[] { "LastModified", "Tags" });
        }
Ejemplo n.º 20
0
        public ActionResult NewJournal()
        {
            var journalDto = new JournalDto();
            List <PlantDAL.EDMX.Plant> plantList = new List <PlantDAL.EDMX.Plant>();

            plantList = PlantCRUD.GetByUserID(User.Identity.GetUserId());
            foreach (var plant in plantList)
            {
                journalDto.Plants.Add(new SelectListItem
                {
                    Text  = plant.Name,
                    Value = plant.ID.ToString()
                });
            }

            return(View(journalDto));
        }
Ejemplo n.º 21
0
        public void FindJournalsByTags()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto   dto   = CreateJournalDto();

            string tag1 = "Journal" + System.Guid.NewGuid().ToString().Substring(0, 12);
            string tag2 = "Journal" + System.Guid.NewGuid().ToString().Substring(0, 12);

            dto.Tags = string.Format("{0},{1}", tag1, tag2);
            proxy.Insert(dto);
            Assert.IsTrue(dto.Uid > 0, "Uid must be > 0 after save.");

            dto      = CreateJournalDto();
            dto.Tags = string.Format("{0},{1}", tag1, tag2);
            proxy.Insert(dto);
            Assert.IsTrue(dto.Uid > 0, "Uid must be > 0 after save.");
        }
Ejemplo n.º 22
0
        public void TestInsertMultiCcy1()
        {
            JournalProxy proxy  = new JournalProxy();
            JournalDto   insert = CreateJournalDto2();

            proxy.Insert(insert);
            Assert.IsTrue(insert.Uid > 0, "Uid must be > 0 after save.");

            JournalDto read = (JournalDto)proxy.GetByUid(insert.Uid);

            Assert.IsTrue(read.FCToBCFXRate > 0, "FX Rate should have been auto-populated.");

            // For comparison, set the original rate to the one set by Saasu.
            insert.FCToBCFXRate = read.FCToBCFXRate;

            ReflectionTester.AssertAreEqual("Journal", insert, read, new[] { "LastModified", "Tags" });
        }
Ejemplo n.º 23
0
        public async Task Update_JournalFound_DuplicateTitle_ThrowsDuplicateJournalException()
        {
            // Arrange
            await PrepareDatabase();

            PopulateJournals();

            // Act & assert
            var journal = new JournalDto {
                Id = 1L, Title = "Journal 1", UserId = "UserId"
            };
            var service = new JournalService(_context);

            service
            .Invoking(s => s.Update(journal))
            .Should()
            .Throw <DuplicateJournalException>();
        }
Ejemplo n.º 24
0
        public void Delete()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto   dto   = CreateJournalDto();

            proxy.Insert(dto);

            proxy.DeleteByUid(dto.Uid);

            try
            {
                JournalDto fromDB = (JournalDto)proxy.GetByUid(dto.Uid);
                Assert.Fail("The Journal Entry was not deleted successfully.");
            }
            catch (RestException ex)
            {
                Assert.IsTrue(ex.Type == "RecordNotFoundException");
            }
        }
Ejemplo n.º 25
0
        public async Task Update_JournalFound_UpdateSuccessful_ReturnsOk()
        {
            var journal = new JournalDto
            {
                Id     = 1L,
                Title  = "Some Journal",
                UserId = "UserId"
            };

            _mockService.Setup(s =>
                               s.Update(It.IsAny <JournalDto>()))
            .ReturnsAsync(journal);

            _controller = new JournalsController(_mockService.Object, _logger);

            var result = await _controller.Update(journal.Id, journal);

            result.Should().BeOfType <OkObjectResult>();
        }
Ejemplo n.º 26
0
        public async Task <JournalDto> Update(JournalDto updatedJournal)
        {
            var journal = await _context.Journals.FindAsync(updatedJournal.Id);

            if (journal == null)
            {
                throw new JournalNotFoundException($"Journal not found: {updatedJournal.Title}");
            }
            if (journal.Title == updatedJournal.Title)
            {
                throw new DuplicateJournalException($"Journal already exists: {updatedJournal.Title}");
            }

            journal.Title        = updatedJournal.Title;
            journal.LastModified = DateTime.Now;
            _context.Journals.Update(journal);
            await _context.SaveChangesAsync();

            return(new JournalDto(journal));
        }
Ejemplo n.º 27
0
        public void FindJournalsForAPeriod()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto   dto1  = CreateJournalDto();

            dto1.Date = DateTime.Parse("01-Jan-2010");
            proxy.Insert(dto1);

            JournalDto dto2 = CreateJournalDto();

            dto2.Date = DateTime.Parse("30-Jan-2010");
            proxy.Insert(dto2);

            NameValueCollection queries = new NameValueCollection();

            queries.Add("JournalDateFrom", "2010/01/01");
            queries.Add("JournalDateTo", "2010/01/30");

            XmlDocument list = proxy.Find(queries);
        }
Ejemplo n.º 28
0
        public async Task Add_UserFound_UniqueTitle_JournalAdded_ReturnsOk()
        {
            const string userId     = "UserId";
            const string title      = "Squeaky New Journal";
            var          journalDto = new JournalDto
            {
                Title  = title,
                UserId = userId
            };

            _mockService.Setup(s =>
                               s.Add(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(journalDto);

            _controller = new JournalsController(_mockService.Object, _logger);

            var result = await _controller.Add(userId, new NewJournalDto { Title = title });

            result.Should().BeOfType <OkObjectResult>();
        }
Ejemplo n.º 29
0
        public JournalDto CreateDtoFromEntity(Journal entity)
        {
            var dto = new JournalDto();

            dto.OrganizationUid  = entity.OrganizationUid;
            dto.OrganizationName = entity.OrganizationName;

            if (entity.IntegrationUid.HasValue)
            {
                dto.IntegrationUid  = entity.IntegrationUid.Value;
                dto.IntegrationName = entity.IntegrationName;
            }

            if (entity.UserUid.HasValue)
            {
                dto.UserUid  = entity.UserUid.Value;
                dto.UserName = entity.UserName;
            }

            dto.Message   = entity.Message;
            dto.CreatedAt = entity.CreatedAt;
            return(dto);
        }
Ejemplo n.º 30
0
        public static List <Images> MapHTTPToImage(List <HttpPostedFileBase> httpImages, JournalDto journal, string serverPath)
        {
            List <Images> imgList = new List <Images>();

            var plantDir = serverPath;

            if (!Directory.Exists(plantDir))
            {
                Directory.CreateDirectory(plantDir);
            }

            foreach (HttpPostedFileBase file in journal.Images)
            {
                Guid imageId = Guid.NewGuid();
                if (file != null)
                {
                    string extension      = Path.GetExtension(file.FileName);
                    var    ServerSavePath = Path.Combine(plantDir, imageId + extension);

                    Images img = new Images();
                    img.ID            = imageId;
                    img.ImageFilePath = ServerSavePath;
                    img.JournalID     = journal.ID;
                    //ImageCRUD.Insert(img);

                    file.SaveAs(ServerSavePath);

                    imgList.Add(img);
                }
            }

            return(imgList);
        }