public void CategoryConstructorReturnsMatchingInformationTest()
        {
            var category = Model.Create <Category>();

            var sut = new PublicCategory(category);

            sut.Should().BeEquivalentTo(category, opt => opt.ExcludingMissingMembers());
        }
        public void CanCreateDefaultInstanceTest()
        {
            var sut = new PublicCategory();

            sut.Group.Should().Be(CategoryGroup.Skill);
            sut.LinkCount.Should().Be(0);
            sut.Name.Should().BeNull();
        }
Esempio n. 3
0
        /// <summary>
        ///     Serializes the promotions result list flatcats.
        /// </summary>
        /// <param name="flatCatId">The flat cat identifier.</param>
        /// <param name="direct">if set to <c>true</c> [direct].</param>
        /// <param name="message">The message.</param>
        internal static void SerializePromotionsResultListFlatcats(int flatCatId, bool direct, ServerMessage message)
        {
            PublicCategory flatCat = Yupi.GetGame().GetNavigator().GetFlatCat(flatCatId);

            message.AppendString("new_ads");
            message.AppendString(flatCat.Caption);
            message.AppendInteger(0);
            message.AppendBool(true);
            message.AppendInteger(-1);

            KeyValuePair <RoomData, uint>[] rooms = Yupi.GetGame().GetRoomManager().GetEventRooms();
            Yupi.GetGame().GetNavigator().SerializeNavigatorPopularRoomsNews(ref message, rooms, flatCatId, direct);
        }
        public async Task <IActionResult> Get(string group, string name, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(group))
            {
                return(new ErrorMessageResult("No category group specified.", HttpStatusCode.NotFound));
            }

            if (Enum.TryParse <CategoryGroup>(group, true, out var categoryGroup) == false)
            {
                return(new ErrorMessageResult("Category group specified is invalid.", HttpStatusCode.NotFound));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                return(new ErrorMessageResult("No category name specified.", HttpStatusCode.NotFound));
            }

            var readType = ReadType.VisibleOnly;

            // Check if there is an authenticated user who is an administrator
            // Administrators will receive the full category with all the properties
            // Non administrators (both anonymous users and authenticated users) will receive
            // only a visible category with only the public properties being returned
            var isAdministrator = IsAdministrator();

            if (isAdministrator)
            {
                readType = ReadType.All;
            }

            var category = await _query.GetCategory(readType, categoryGroup, name, cancellationToken)
                           .ConfigureAwait(false);

            if (category == null)
            {
                return(new ErrorMessageResult("The requested category does not exist.", HttpStatusCode.NotFound));
            }

            if (isAdministrator)
            {
                return(new OkObjectResult(category));
            }

            var publicCategory = new PublicCategory(category);

            return(new OkObjectResult(publicCategory));
        }
Esempio n. 5
0
        /// <summary>
        ///     Serializes the search result list flatcats.
        /// </summary>
        /// <param name="flatCatId">The flat cat identifier.</param>
        /// <param name="direct">if set to <c>true</c> [direct].</param>
        /// <param name="message">The message.</param>
        internal static void SerializeSearchResultListFlatcats(int flatCatId, bool direct, ServerMessage message)
        {
            PublicCategory flatCat = Yupi.GetGame().GetNavigator().GetFlatCat(flatCatId);

            if (flatCat == null)
            {
                return;
            }

            message.AppendString($"category__{flatCat.Caption}");
            message.AppendString(flatCat.Caption);
            message.AppendInteger(0);
            message.AppendBool(true);
            message.AppendInteger(-1);

            KeyValuePair <RoomData, uint>[] rooms = Yupi.GetGame().GetRoomManager().GetActiveRooms();
            Yupi.GetGame().GetNavigator().SerializeNavigatorPopularRoomsNews(ref message, rooms, flatCatId, direct);
        }