private void MapMsd1ToMsd1Data()
        {
            Msd1Data = _context.Msd1Data.FirstOrDefault(x => x.Msd1Id == MSD1.Msd1Id) ?? new Msd1Data();

            Msd1Data.Msd1Id         = MSD1.Msd1Id ?? _helperService.GetUniqueKey();
            Msd1Data.Imo            = MSD1.Imo;
            Msd1Data.ShipName       = MSD1.ShipName;
            Msd1Data.FlagCode       = MSD1.FlagCode;
            Msd1Data.Year           = MSD1.Year;
            Msd1Data.Quarter        = MSD1.Quarter;
            Msd1Data.AssociatedPort = _helperService.GetPortCodeByPort(MSD1.AssociatedPort) ?? MSD1.AssociatedPort;
            Msd1Data.ReportingPort  = _helperService.GetPortCodeByPort(MSD1.ReportingPort) ?? MSD1.ReportingPort;
            Msd1Data.NumVoyages     = MSD1.NumVoyages;
            Msd1Data.IsInbound      = MSD1.IsInbound == null ? false : MSD1.IsInbound.Value;
            Msd1Data.VoyageDate     = MSD1.VoyageDate;
            Msd1Data.UserName       = Msd1Data.UserName ?? _userManager.GetUserName(HttpContext.User);
            Msd1Data.DataSourceId   = (int)DataSource.WEB;
            Msd1Data.CreatedDate    = Msd1Data.CreatedDate != default(DateTime) && Msd1Data.CreatedDate < DateTime.Now ?
                                      Msd1Data.CreatedDate : DateTime.SpecifyKind(currentDateTime, DateTimeKind.Utc);
            Msd1Data.LastUpdatedBy = _userManager.GetUserName(HttpContext.User);
            Msd1Data.ModifiedDate  = DateTime.SpecifyKind(currentDateTime, DateTimeKind.Utc);
            Msd1Data.AgentSenderId = MSD1.AgentSenderID;
            Msd1Data.LineSenderId  = MSD1.LineSenderID;
            Msd1Data.RecordRef     = MSD1.RecordRef;

            Msd1Data.Msd1CargoSummary = _context.Msd1CargoSummary.Where(x => x.Msd1Id == Msd1Data.Msd1Id)
                                        .ToList();

            if (Msd1Data.Msd1CargoSummary.Count > 0)
            {
                Msd1Data.Msd1CargoSummary.Clear();
            }

            foreach (CargoItem item in MSD1.CargoSummary)
            {
                Msd1CargoSummary msd1CargoSummary = new Msd1CargoSummary
                {
                    Msd1Id            = Msd1Data.Msd1Id,
                    CategoryCode      = _helperService.GetCategoryCodeByDescription(item.Category),
                    UnitsWithCargo    = item.UnitsWithCargo,
                    UnitsWithoutCargo = item.UnitsWithoutCargo,
                    TotalUnits        = item.TotalUnits,
                    GrossWeight       = (decimal?)item.GrossWeight,
                    Description       = item.Description
                };

                Msd1Data.Msd1CargoSummary.Add(msd1CargoSummary);
            }
            ;
        }
        public async Task IsValidCategory_WhenPassed_ShouldReturnValidCode()
        {
            string strcategory1   = "Crude Oil";
            string strcategory2   = "Oil Products";
            byte   categoryCode12 = 12;
            byte   categoryCode13 = 13;
            byte   groupCode      = 10;

            var CargoGroup = new CargoGroup()
            {
                Description   = strcategory1,
                IsUnitised    = true,
                GroupCode     = groupCode,
                CargoCategory = new List <CargoCategory>()
            };

            var CargoCategories = new List <CargoCategory>()
            {
                new CargoCategory {
                    GroupCode = groupCode, CategoryCode = categoryCode12, Description = strcategory1
                },
                new CargoCategory {
                    GroupCode = groupCode, CategoryCode = categoryCode13, Description = strcategory2
                }
            };

            await actualContext.CargoGroup.AddRangeAsync(CargoGroup);

            await actualContext.CargoCategory.AddRangeAsync(CargoCategories);

            actualContext.SaveChanges();

            var result   = _helperService.GetCategoryCodeByDescription(strcategory1);
            var category = CargoCategories.Find(x => x.Description == strcategory1).CategoryCode;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(byte));
            Assert.IsNotNull(category);
            Assert.AreEqual(result, category);
        }