示例#1
0
            public async Task Get_watchers_by_costId()
            {
                // Arrange
                var costId       = Guid.NewGuid();
                var firstUserId  = Guid.NewGuid();
                var secondUserId = Guid.NewGuid();

                var notificationSubscribers = new List <NotificationSubscriber>
                {
                    new NotificationSubscriber
                    {
                        Id         = Guid.NewGuid(),
                        CostId     = costId,
                        CostUserId = firstUserId,
                        CostUser   = new CostUser
                        {
                            Id                = firstUserId,
                            FirstName         = "Clark",
                            LastName          = "Kent",
                            UserBusinessRoles = new List <UserBusinessRole>
                            {
                                new UserBusinessRole
                                {
                                    BusinessRole = new BusinessRole
                                    {
                                        Value = "Super Man"
                                    }
                                }
                            }
                        }
                    },
                    new NotificationSubscriber
                    {
                        Id         = Guid.NewGuid(),
                        CostId     = costId,
                        CostUserId = secondUserId,
                        CostUser   = new CostUser
                        {
                            Id                = secondUserId,
                            FirstName         = "Bruce",
                            LastName          = "Wayne",
                            UserBusinessRoles = new List <UserBusinessRole>
                            {
                                new UserBusinessRole
                                {
                                    BusinessRole = new BusinessRole
                                    {
                                        Value = "Bat Man"
                                    }
                                }
                            }
                        }
                    }
                };

                EFContext.NotificationSubscriber.AddRange(notificationSubscribers);
                await EFContext.SaveChangesAsync();

                Mapper.Setup(m => m.Map <List <CostWatcherModel> >(It.IsAny <List <NotificationSubscriber> >())).Returns(new List <CostWatcherModel>
                {
                    new CostWatcherModel
                    {
                        BusinessRoles = new List <BusinessRoleModel>
                        {
                            new BusinessRoleModel
                            {
                                Value = "Super Man"
                            }
                        },
                        CostId   = costId,
                        FullName = "Clark Kent",
                        UserId   = firstUserId,
                        Owner    = true
                    },
                    new CostWatcherModel
                    {
                        BusinessRoles = new List <BusinessRoleModel>
                        {
                            new BusinessRoleModel
                            {
                                Value = "Bat Man"
                            }
                        },
                        CostId   = costId,
                        FullName = "Bruce Wayne",
                        UserId   = secondUserId,
                        Owner    = false
                    }
                });
                // Act
                var watchers = await CostService.GetCostWatchers(costId);

                // Assert
                watchers.Count.Should().Be(2);
                watchers.First().BusinessRoles.First().Value.Should().Be("Super Man");
                watchers.Last().BusinessRoles.First().Value.Should().Be("Bat Man");
                watchers.First().Owner.Should().Be(true);
                watchers.Last().Owner.Should().Be(false);
            }