public void TooLongName_TruncatesName()
            {
                // arrange
                var expected = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
                var repo     = MakeRepo();
                var test     = new CustomListHeader()
                {
                    UserId         = new Guid("0dd15d06-7476-4ec9-9d2c-a78da51fc8bf"),
                    Active         = true,
                    BranchId       = "FDF",
                    CustomerNumber = "100234",
                    Name           = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901",
                    CreatedUtc     = new DateTime(2017, 6, 23, 16, 13, 0, DateTimeKind.Utc),
                    ModifiedUtc    = new DateTime(2017, 6, 23, 16, 14, 0, DateTimeKind.Utc)
                };

                // act
                var headerId = repo.SaveCustomListHeader(test);
                var results  = repo.GetCustomListHeader(headerId);

                // assert
                results.Name
                .Should()
                .Be(expected);
            }
예제 #2
0
        public static ListModel ToListModel(this CustomListHeader header, UserSelectedContext catalogInfo, List <CustomListShare> shares)
        {
            ListModel retVal = new ListModel();

            retVal.BranchId          = header.BranchId;
            retVal.CustomerNumber    = header.CustomerNumber;
            retVal.IsContractList    = false;
            retVal.IsFavorite        = false;
            retVal.IsWorksheet       = false;
            retVal.IsReminder        = false;
            retVal.IsMandatory       = false;
            retVal.IsRecommended     = false;
            retVal.IsCustomInventory = false;
            retVal.Type = ListType.Custom;

            if (shares != null)
            {
                retVal.SharedWith = shares.Select(s => s.CustomerNumber)
                                    .ToList();
            }

            retVal.ListId    = header.Id;
            retVal.Name      = (header != null && header.Name != null) ? header.Name : "(No set name)";
            retVal.ReadOnly  = !header.CustomerNumber.Equals(catalogInfo.CustomerId);
            retVal.IsSharing = shares != null &&
                               (shares.Any() &&
                                header.CustomerNumber.Equals(catalogInfo.CustomerId) &&
                                header.BranchId.Equals(catalogInfo.BranchId, StringComparison.CurrentCultureIgnoreCase));
            retVal.IsShared = !header.CustomerNumber.Equals(catalogInfo.CustomerId);

            return(retVal);
        }
            public void ShortCustomerNumber_ShouldPadRightWithSpaces()
            {
                // arrange
                var expected = "1     ";
                var repo     = MakeRepo();
                var test     = new CustomListHeader()
                {
                    UserId         = new Guid("0dd15d06-7476-4ec9-9d2c-a78da51fc8bf"),
                    BranchId       = "FDF",
                    Active         = true,
                    CustomerNumber = "1",
                    Name           = "Fake Custom List",
                    CreatedUtc     = new DateTime(2017, 6, 23, 16, 13, 0, DateTimeKind.Utc),
                    ModifiedUtc    = new DateTime(2017, 6, 23, 16, 14, 0, DateTimeKind.Utc)
                };

                // act
                var headerId = repo.SaveCustomListHeader(test);
                var results  = repo.GetCustomListHeader(headerId);

                // assert
                results.CustomerNumber
                .Should()
                .Be(expected);
            }
            public void EmptyUserId_SavesWithBadUserId()
            {
                // arrange
                var expected = Guid.Empty;
                var repo     = MakeRepo();
                var test     = new CustomListHeader()
                {
                    UserId         = Guid.Empty,
                    Active         = true,
                    BranchId       = "FDF",
                    CustomerNumber = "100234",
                    Name           = "Fake Custom List",
                    CreatedUtc     = new DateTime(2017, 6, 23, 16, 13, 0, DateTimeKind.Utc),
                    ModifiedUtc    = new DateTime(2017, 6, 23, 16, 14, 0, DateTimeKind.Utc)
                };

                // act
                var headerId = repo.SaveCustomListHeader(test);
                var results  = repo.GetCustomListHeader(headerId);

                // assert
                results.UserId
                .Should()
                .Be(expected);
            }
예제 #5
0
        public static ListModel ToListModel(this CustomListHeader header, UserSelectedContext catalogInfo, List <CustomListShare> shares,
                                            List <ListItemModel> items)
        {
            ListModel retVal = header.ToListModel(catalogInfo, shares);

            retVal.Items = items.OrderBy(l => l.Position)
                           .ToList();
            return(retVal);
        }
예제 #6
0
            public void IniatlizedItem_HasDefaultValue()
            {
                // arrange
                CustomListHeader test = new CustomListHeader();

                // act

                // assert
                test.UserId
                .Should()
                .BeNull();
            }
예제 #7
0
        private ListModel GetCompletedModel(CustomListHeader header, UserSelectedContext catalogInfo, bool headerOnly)
        {
            List <CustomListDetail> items  = null;
            List <CustomListShare>  shares = null;

            if (!headerOnly)
            {
                items  = _detailsRepo.GetCustomListDetails(header.Id);
                shares = _sharesRepo.GetCustomListSharesByHeaderId(header.Id);
            }

            return(header.ToListModel(catalogInfo, shares, items));
        }
예제 #8
0
            public void GoodItem_ReturnsDefaultValue()
            {
                // arrange
                CustomListHeader fakeItem = MakeHeader();
                Guid             expected = new Guid("a08bb907-ab8e-4e56-9f22-b94b3d6a08e3");

                // act

                // assert
                fakeItem.UserId
                .Should()
                .Be(expected);
            }
예제 #9
0
            public void GoodItem_ReturnsDefaultValue()
            {
                // arrange
                CustomListHeader fakeItem = MakeHeader();
                string           expected = "Fake Name";

                // act

                // assert
                fakeItem.Name
                .Should()
                .Be(expected);
            }
예제 #10
0
            public void IniatlizedItem_HasDefaultValue()
            {
                // arrange
                CustomListHeader test     = new CustomListHeader();
                bool             expected = false;

                // act

                // assert
                test.Active
                .Should()
                .Be(expected);
            }
예제 #11
0
            public void GoodItem_ReturnsDefaultValue()
            {
                // arrange
                CustomListHeader fakeItem = MakeHeader();
                bool             expected = true;

                // act

                // assert
                fakeItem.Active
                .Should()
                .Be(expected);
            }
예제 #12
0
        public static ListModel ToListModel(this CustomListHeader header, UserSelectedContext catalogInfo, List <CustomListShare> shares,
                                            List <CustomListDetail> items)
        {
            ListModel retVal = header.ToListModel(catalogInfo, shares);

            if (items != null)
            {
                retVal.Items = items.Select(i => i.ToWebModel())
                               .OrderBy(l => l.Position)
                               .ToList();
            }

            return(retVal);
        }
예제 #13
0
        public long SaveCustomListHeader(CustomListHeader model)
        {
            DynamicParameters parms = new DynamicParameters();

            parms.Add(PARMNAME_ACTIVE, model.Active);
            parms.Add(PARMNAME_BRANCH, model.BranchId);
            parms.Add(PARMNAME_CUSTNUM, model.CustomerNumber);
            parms.Add(PARMNAME_ID, model.Id);
            parms.Add(PARMNAME_NAME, model.Name);
            parms.Add(PARMNAME_USERID, model.UserId);
            parms.Add(PARMNAME_RETVAL, direction: ParameterDirection.Output, dbType: DbType.Int64);

            ExecuteSPCommand(SPNAME_SAVE, parms);

            return(parms.Get <long>(PARMNAME_RETVAL));
        }
            public void NullName_ThrowsException()
            {
                // arrange
                var repo = MakeRepo();
                var test = new CustomListHeader()
                {
                    UserId         = new Guid("0dd15d06-7476-4ec9-9d2c-a78da51fc8bf"),
                    Active         = true,
                    BranchId       = "FDF",
                    CustomerNumber = "100234",
                    CreatedUtc     = new DateTime(2017, 6, 23, 16, 13, 0, DateTimeKind.Utc),
                    ModifiedUtc    = new DateTime(2017, 6, 23, 16, 14, 0, DateTimeKind.Utc)
                };

                // act
                Action act = () => repo.SaveCustomListHeader(test);

                // assert
                act.Should().Throw <SqlException>();
            }
            public void NullUserId_SavesCorrectly()
            {
                // arrange
                var repo = MakeRepo();
                var test = new CustomListHeader()
                {
                    Active         = true,
                    BranchId       = "FDF",
                    CustomerNumber = "100234",
                    Name           = "Fake Custom List",
                    CreatedUtc     = new DateTime(2017, 6, 23, 16, 13, 0, DateTimeKind.Utc),
                    ModifiedUtc    = new DateTime(2017, 6, 23, 16, 14, 0, DateTimeKind.Utc)
                };

                // act
                var headerId = repo.SaveCustomListHeader(test);
                var results  = repo.GetCustomListHeader(headerId);

                // assert
                results.UserId
                .Should()
                .BeNull();
            }
예제 #16
0
        public ListModel ReadList(long listId, UserSelectedContext catalogInfo, bool headerOnly)
        {
            CustomListHeader header = _headersRepo.GetCustomListHeader(listId);

            return(header == null ? null : GetCompletedModel(header, catalogInfo, headerOnly));
        }