Beispiel #1
0
        public async Task CreateGroup_ReturnsCreatedGroup()
        {
            var group = new GroupInputViewModel
            {
                Name = "Group"
            };
            var service = new Mock <IGroupService>();

            service.Setup(x => x.AddGroup(It.Is <Group>(g => g.Name == group.Name)))
            .Returns(Task.FromResult(new Group
            {
                Id   = 2,
                Name = group.Name
            }))
            .Verifiable();

            var controller = new GroupsController(service.Object, Mapper.Instance);

            var result      = (await controller.CreateGroup(group)).Result as CreatedAtActionResult;
            var resultValue = result.Value as GroupViewModel;

            Assert.IsNotNull(resultValue);
            Assert.AreEqual(2, resultValue.Id);
            Assert.AreEqual("Group", resultValue.Name);
            service.VerifyAll();
        }
Beispiel #2
0
        public async Task CreateGroupController_GroupNotExist_ReturnsConflict()
        {
            // Arrange
            var controller = new GroupsController(new GroupRepositoryStub(), new UserRepositoryStub(),
                                                  new SmartLockRepositoryStub(), new AzureAdRepositoryStub(), _mapper);

            var groupCreationDto = new GroupCreationDto
            {
                Id              = Guid.Parse("c374cb18-862e-4fef-871f-ae08337d1f76"),
                Status          = Status.Active,
                SmartLockGroups = new List <SmartLockCollectionDto>
                {
                    new SmartLockCollectionDto
                    {
                        SmartLockId = Guid.Parse("3fa85f64-5717-4562-b3fc-2c963f66afa6")
                    }
                }
            };

            // Act
            var result = await controller.CreateGroup(groupCreationDto);

            // Assert
            Assert.IsInstanceOfType(result.Result, typeof(ConflictObjectResult));
        }
        private void CreateGroupIdToChannelNameDic()
        {
            groupToAddtionalChannelDic = new Dictionary <string, string>();
            Dictionary <string, string> countyToAlertDic = CreateCountyToAlertDic();
            IEnumerable <AADIdentity>   groups           = groupsController.GetGroups(graphClientManager.GetGraphHttpClient())
                                                           .GetAwaiter().GetResult();

            foreach (string countyName in countyToAlertDic.Keys)
            {
                bool groupAlreayCreated = false;
                foreach (AADIdentity identity in groups)
                {
                    if (identity.DisplayName.Equals(countyName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        groupToAddtionalChannelDic.Add(identity.Id, countyToAlertDic[countyName]);
                        groupAlreayCreated = true;
                        break;
                    }
                }

                if (!groupAlreayCreated)
                {
                    AADIdentity group = groupsController
                                        .CreateGroup(graphClientManager.GetGraphHttpClient(), countyName).GetAwaiter().GetResult();
                    groupToAddtionalChannelDic.Add(group.Id, countyToAlertDic[countyName]);
                }
            }
        }
Beispiel #4
0
        public async Task CreateGroup_RequiresGroup()
        {
            var service    = new Mock <IGroupService>(MockBehavior.Strict);
            var controller = new GroupsController(service.Object, Mapper.Instance);

            var result = (await controller.CreateGroup(null)).Result as BadRequestResult;

            Assert.IsNotNull(result);
        }