コード例 #1
0
        public void Update(WorkTag tag, int memberID)
        {
            if (!IsMember(tag.WorkID, memberID))
            {
                throw new ArgumentOutOfRangeException();
            }
            if (tag == null)
            {
                throw new ArgumentNullException(nameof(tag));
            }

            var scriptGet = @"SELECT * FROM work_tag WHERE WorkTagID = @WorkTagID AND RemovedDate IS NULL";

            if (DB.QuerySingle <WorkTag>(scriptGet, tag) == null)
            {
                throw new ArgumentOutOfRangeException();
            }

            var script = @"UPDATE work_tag
            SET
            `Title` = @Title,
            `Value` = @Value,
            `Color` = @Color,
            `UpdatedBy` = @UpdatedBy,
            `UpdatedDate` = NOW()
            WHERE `WorkTagID` = @WorkTagID;";

            tag.UpdatedBy = memberID;
            DB.Execute(script, tag);
        }
コード例 #2
0
        private void OnAddTag()
        {
            WorkTag tag = new WorkTag(NewTag, NewValue);

            NewEntry.Tags.Add(tag);
            CurrentTags.Add(tag);
            NewTag   = "";
            NewValue = "";
        }
コード例 #3
0
 private void OnRemoveLastTag()
 {
     if (NewEntry.Tags.Count > 0)
     {
         WorkTag temp = NewEntry.Tags[NewEntry.Tags.Count - 1];
         NewBook.EntryTags.Remove(temp.Name);
         NewEntry.Tags.RemoveAt(NewEntry.Tags.Count - 1);
         CurrentTags.RemoveAt(CurrentTags.Count - 1);
     }
 }
コード例 #4
0
        public int Insert(WorkTag tag, int memberID)
        {
            if (tag == null)
            {
                throw new ArgumentNullException(nameof(tag));
            }

            if (!IsMember(tag.WorkID, memberID))
            {
                throw new ArgumentOutOfRangeException();
            }

            tag.CreatedBy = memberID;
            tag.UpdatedBy = memberID;

            var script = @"INSERT INTO work_tag
                ( WorkID,Title,`Value`,Color,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate )
                VALUES
                ( @WorkID, @Title, @Value, @Color, @CreatedBy, NOW(), @UpdatedBy, NOW() );
                SELECT LAST_INSERT_ID();";

            return(DB.QuerySingle <int>(script, tag));
        }
コード例 #5
0
        public async Task Can_create_resource_with_attributes_and_multiple_relationship_types()
        {
            // Arrange
            List <UserAccount> existingUserAccounts = _fakers.UserAccount.Generate(2);
            WorkTag            existingTag          = _fakers.WorkTag.Generate();

            string newDescription = _fakers.WorkItem.Generate().Description;

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                dbContext.UserAccounts.AddRange(existingUserAccounts);
                dbContext.WorkTags.Add(existingTag);
                await dbContext.SaveChangesAsync();
            });

            var requestBody = new
            {
                data = new
                {
                    type       = "workItems",
                    attributes = new
                    {
                        description = newDescription
                    },
                    relationships = new
                    {
                        assignee = new
                        {
                            data = new
                            {
                                type = "userAccounts",
                                id   = existingUserAccounts[0].StringId
                            }
                        },
                        subscribers = new
                        {
                            data = new[]
                            {
                                new
                                {
                                    type = "userAccounts",
                                    id   = existingUserAccounts[1].StringId
                                }
                            }
                        },
                        tags = new
                        {
                            data = new[]
                            {
                                new
                                {
                                    type = "workTags",
                                    id   = existingTag.StringId
                                }
                            }
                        }
                    }
                }
            };

            const string route = "/workItems";

            // Act
            (HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAsync <Document>(route, requestBody);

            // Assert
            httpResponse.Should().HaveStatusCode(HttpStatusCode.Created);

            responseDocument.SingleData.Should().NotBeNull();
            responseDocument.SingleData.Attributes["description"].Should().Be(newDescription);
            responseDocument.SingleData.Relationships.Should().NotBeEmpty();

            int newWorkItemId = int.Parse(responseDocument.SingleData.Id);

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                // @formatter:wrap_chained_method_calls chop_always
                // @formatter:keep_existing_linebreaks true

                WorkItem workItemInDatabase = await dbContext.WorkItems
                                              .Include(workItem => workItem.Assignee)
                                              .Include(workItem => workItem.Subscribers)
                                              .Include(workItem => workItem.WorkItemTags)
                                              .ThenInclude(workItemTag => workItemTag.Tag)
                                              .FirstWithIdAsync(newWorkItemId);

                // @formatter:keep_existing_linebreaks restore
                // @formatter:wrap_chained_method_calls restore

                workItemInDatabase.Description.Should().Be(newDescription);

                workItemInDatabase.Assignee.Should().NotBeNull();
                workItemInDatabase.Assignee.Id.Should().Be(existingUserAccounts[0].Id);

                workItemInDatabase.Subscribers.Should().HaveCount(1);
                workItemInDatabase.Subscribers.Single().Id.Should().Be(existingUserAccounts[1].Id);

                workItemInDatabase.WorkItemTags.Should().HaveCount(1);
                workItemInDatabase.WorkItemTags.Single().Tag.Id.Should().Be(existingTag.Id);
            });
        }
コード例 #6
0
        public async Task Can_replace_HasManyThrough_relationship_with_include_and_fieldsets()
        {
            // Arrange
            WorkItem existingWorkItem = _fakers.WorkItem.Generate();
            WorkTag  existingTag      = _fakers.WorkTag.Generate();

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                dbContext.AddRange(existingWorkItem, existingTag);
                await dbContext.SaveChangesAsync();
            });

            var requestBody = new
            {
                data = new
                {
                    type          = "workItems",
                    id            = existingWorkItem.StringId,
                    relationships = new
                    {
                        tags = new
                        {
                            data = new[]
                            {
                                new
                                {
                                    type = "workTags",
                                    id   = existingTag.StringId
                                }
                            }
                        }
                    }
                }
            };

            string route = $"/workItems/{existingWorkItem.StringId}?fields[workItems]=priority,tags&include=tags&fields[workTags]=text";

            // Act
            (HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePatchAsync <Document>(route, requestBody);

            // Assert
            httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);

            responseDocument.SingleData.Should().NotBeNull();
            responseDocument.SingleData.Type.Should().Be("workItems");
            responseDocument.SingleData.Id.Should().Be(existingWorkItem.StringId);
            responseDocument.SingleData.Attributes.Should().HaveCount(1);
            responseDocument.SingleData.Attributes["priority"].Should().Be(existingWorkItem.Priority.ToString("G"));
            responseDocument.SingleData.Relationships.Should().HaveCount(1);
            responseDocument.SingleData.Relationships["tags"].ManyData.Should().HaveCount(1);
            responseDocument.SingleData.Relationships["tags"].ManyData[0].Id.Should().Be(existingTag.StringId);

            responseDocument.Included.Should().HaveCount(1);
            responseDocument.Included[0].Type.Should().Be("workTags");
            responseDocument.Included[0].Id.Should().Be(existingTag.StringId);
            responseDocument.Included[0].Attributes.Should().HaveCount(1);
            responseDocument.Included[0].Attributes["text"].Should().Be(existingTag.Text);
            responseDocument.Included[0].Relationships.Should().BeNull();

            int newWorkItemId = int.Parse(responseDocument.SingleData.Id);

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                // @formatter:wrap_chained_method_calls chop_always
                // @formatter:keep_existing_linebreaks true

                WorkItem workItemInDatabase = await dbContext.WorkItems
                                              .Include(workItem => workItem.WorkItemTags)
                                              .ThenInclude(workItemTag => workItemTag.Tag)
                                              .FirstWithIdAsync(newWorkItemId);

                // @formatter:keep_existing_linebreaks restore
                // @formatter:wrap_chained_method_calls restore

                workItemInDatabase.WorkItemTags.Should().HaveCount(1);
                workItemInDatabase.WorkItemTags.Single().Tag.Id.Should().Be(existingTag.Id);
            });
        }
コード例 #7
0
 public int Post([FromBody] WorkTag tag) => _workTagDatasource.Insert(tag, CurrentMemberID);
コード例 #8
0
 public void Put([FromBody] WorkTag tag) => _workTagDatasource.Update(tag, CurrentMemberID);
コード例 #9
0
        public async Task Can_remove_from_HasManyThrough_relationship_with_unassigned_existing_resource()
        {
            // Arrange
            WorkItem existingWorkItem = _fakers.WorkItem.Generate();

            existingWorkItem.WorkItemTags = new[]
            {
                new WorkItemTag
                {
                    Tag = _fakers.WorkTag.Generate()
                },
                new WorkItemTag
                {
                    Tag = _fakers.WorkTag.Generate()
                }
            };

            WorkTag existingTag = _fakers.WorkTag.Generate();

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                await dbContext.ClearTableAsync <WorkTag>();
                dbContext.AddRange(existingWorkItem, existingTag);
                await dbContext.SaveChangesAsync();
            });

            var requestBody = new
            {
                data = new[]
                {
                    new
                    {
                        type = "workTags",
                        id   = existingWorkItem.WorkItemTags.ElementAt(1).Tag.StringId
                    },
                    new
                    {
                        type = "workTags",
                        id   = existingTag.StringId
                    }
                }
            };

            string route = $"/workItems/{existingWorkItem.StringId}/relationships/tags";

            // Act
            (HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecuteDeleteAsync <string>(route, requestBody);

            // Assert
            httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);

            responseDocument.Should().BeEmpty();

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                // @formatter:wrap_chained_method_calls chop_always
                // @formatter:keep_existing_linebreaks true

                WorkItem workItemInDatabase = await dbContext.WorkItems
                                              .Include(workItem => workItem.WorkItemTags)
                                              .ThenInclude(workItemTag => workItemTag.Tag)
                                              .FirstWithIdAsync(existingWorkItem.Id);

                // @formatter:keep_existing_linebreaks restore
                // @formatter:wrap_chained_method_calls restore

                workItemInDatabase.WorkItemTags.Should().HaveCount(1);
                workItemInDatabase.WorkItemTags.Single().Tag.Id.Should().Be(existingWorkItem.WorkItemTags.ElementAt(0).Tag.Id);

                List <WorkTag> tagsInDatabase = await dbContext.WorkTags.ToListAsync();
                tagsInDatabase.Should().HaveCount(3);
            });
        }