public async Task GetGroupsByCountry_ShouldReturnStatusOkAndIEnumerableOfGroupDto()
        {
            //Arrange
            var groupServiceMock = Substitute.For <IGroupService>();
            var group            = new Group {
                Id = 1, Name = "someName", Country = "someCountry", CreationYear = 2000
            };
            var expected = new List <GroupDto> {
                GroupDto.GetGroupDtoWithId(1, "someName", "someCountry", 2000)
            };

            groupServiceMock.GetAllAsync().Returns(new List <GroupDto>
            {
                GroupDto.GetGroupDtoWithId(1, "someName", "someCountry", 2000)
            });
            var sut = new GroupsController(groupServiceMock);

            //Act
            var response = await sut.GetGroupsByCountry("someCountry");

            //Assert
            await groupServiceMock.Received().FindOneAsync(g => g.Country == "someCountry");

            //Assert.Equal(200, ((StatusCodeResult) response.Result).StatusCode);
            //Assert.Equal(expected, response.Value);
        }
        public async Task GetAllGroupsAsync_ShouldReturnStatusOkAndListOfGroups()
        {
            //Arrange
            var groupRepoMock = Substitute.For <IGroupRepository>();

            groupRepoMock.GetAllAsync().Returns(new List <Group>
            {
                new Group {
                    Id = 1, Name = "someName", Country = "someCountry", CreationYear = 2000
                }
            });
            var groupServiceMock = Substitute.For <IGroupService>();
            var expected         = new List <GroupDto> {
                GroupDto.GetGroupDtoWithId(1, "someName", "someCountry", 2000)
            };

            groupServiceMock.GetAllAsync().Returns(expected);
            var sut = new GroupsController(groupServiceMock);

            //Act
            var response = await sut.GetAllGroupsAsync();

            //Assert
            await groupServiceMock.Received().GetAllAsync();

            //Assert.Equal(200, ((StatusCodeResult)response).StatusCode)); //need to fix(can`t get statusCode & value from ActionResult) but result is correct
            //Assert.Equal(expected, response.Value);
        }
        public async Task AddAsync_ShouldCallMethodAddAsyncFromRepository()
        {
            //Arrange
            var groupRepoMock = Substitute.For <IGroupRepository>();
            var groupToAdd    = new Group {
                Id = 1, Name = "someName", Country = "someCountry", CreationYear = 1234
            };
            IGroupService sut = new GroupService(groupRepoMock);

            //Act
            await sut.AddAsync(GroupDto.GetGroupDtoWithId(1, "someName", "someCountry", 1234));

            //Assert
            await groupRepoMock.Received().AddAsync(groupToAdd);
        }
        public async Task GetByIdAsync_ShouldReturnGroupDto()
        {
            //Arrange
            var groupRepoMock = Substitute.For <IGroupRepository>();
            var expected      = GroupDto.GetGroupDtoWithId(1, "someName", "someCountry", 1234);

            groupRepoMock.GetByIdAsync(1).Returns(new Group {
                Id = 1, Name = "someName", Country = "someCountry", CreationYear = 1234
            });
            IGroupService sut = new GroupService(groupRepoMock);

            //Act
            var actual = await sut.GetByIdAsync(1);

            //Assert
            await groupRepoMock.Received().GetByIdAsync(1);

            Assert.Equal(actual, expected);
        }
        public async Task GetGroupsByCountry_NotExistingNameNameStatusBadRequest()
        {
            //Arrange
            var groupServiceMock = Substitute.For <IGroupService>();
            var group            = GroupDto.GetGroupDtoWithId(1, "someName", "someCountry", 2000);

            groupServiceMock.GetAllAsync().Returns(new List <GroupDto> {
                group
            });
            //groupServiceMock.FindOneAsync(g => g.Country == "notExistingName").Returns(null);
            var sut = new GroupsController(groupServiceMock);

            //Act
            var response = await sut.GetGroupsByCountry("notExistingName");

            //Assert
            await groupServiceMock.Received().FindOneAsync(g => g.Name == "notExistingName");

            //Assert.Equal(400, ((StatusCodeResult) response.Result).StatusCode);
        }
        public async Task GetGroupByName_ShouldReturnStatusOkAndGroupDto()
        {
            //Arrange
            var groupServiceMock = Substitute.For <IGroupService>();
            var expected         = GroupDto.GetGroupDtoWithId(1, "someName", "someCountry", 2000);

            groupServiceMock.GetAllAsync().Returns(new List <GroupDto> {
                expected
            });
            var sut = new GroupsController(groupServiceMock);

            //Act
            var response = await sut.GetGroupByName("someName");

            //Assert
            await groupServiceMock.Received().FindOneAsync(g => g.Name == "someName");

            //Assert.Equal(200, ((StatusCodeResult) response.Result).StatusCode);
            //Assert.Equal(expected, response.Value);
        }
        public async Task FindOneAsync_ShouldReturnGroupDtoWithSpecifiedPredicate()
        {
            //Arrange
            var groupRepoMock = Substitute.For <IGroupRepository>();
            var groupToFind   = new Group {
                Id = 1, Name = "someName", Country = "someCountry", CreationYear = 1234
            };
            var expected = GroupDto.GetGroupDtoWithId(1, "someName", "someCountry", 1234);

            ;
            groupRepoMock.GetAllAsync().Returns(new List <Group> {
                groupToFind
            });
            IGroupService sut = new GroupService(groupRepoMock);

            //Act
            var actualGroup = await sut.FindOneAsync(g => g.Name == groupToFind.Name).ConfigureAwait(false);

            //Asset
            await groupRepoMock.Received().GetAllAsync();

            Assert.Equal(expected, actualGroup);
        }