public async Task GetByOdsCodeAsync_OrganisationDoesNotExist_ReturnsNotFound()
        {
            using var controller = OdsControllerBuilder
                                   .Create()
                                   .WithGetByOdsCode(null)
                                   .Build();

            var result = await controller.GetByOdsCodeAsync(string.Empty);

            result.Should().BeEquivalentTo(new NotFoundResult());
        }
        public static async Task GetByOdsCodeAsync_OdsOrganisationDoesNotExist_ReturnsNotFound()
        {
            var organisation = OrganisationBuilder.Create(1).WithOdsCode("some-code").Build();

            using var controller = OdsControllerBuilder
                                   .Create()
                                   .WithGetByOdsCode(null, organisation)
                                   .Build();

            var result = await controller.GetByOdsCodeAsync(organisation.OdsCode);

            result.Should().BeEquivalentTo(new NotFoundResult());
        }
        public static async Task GetByOdsCodeAsync_OrganisationIsNotBuyerOrganisation_ReturnsNotAccepted()
        {
            var nonBuyerOrganisation = OdsOrganisationBuilder.Create(1).Build();
            var organisation         = OrganisationBuilder.Create(1).WithOdsCode(nonBuyerOrganisation.OdsCode).Build();

            using var controller = OdsControllerBuilder
                                   .Create()
                                   .WithGetByOdsCode(nonBuyerOrganisation, organisation)
                                   .Build();

            var response = await controller.GetByOdsCodeAsync(nonBuyerOrganisation.OdsCode);

            response.As <StatusCodeResult>().StatusCode.Should().Be((int)StatusCodes.Status406NotAcceptable);
        }
        public async Task GetByOdsCodeAsync_OrganisationIsNotBuyerOrganisation_ReturnsNotAccepted()
        {
            var nonBuyerOrganisation = OdsOrganisationBuilder.Create(1).Build();

            using var controller = OdsControllerBuilder
                                   .Create()
                                   .WithGetByOdsCode(nonBuyerOrganisation)
                                   .Build();

            var response = await controller.GetByOdsCodeAsync("dolor eternum");

            response.Should().BeOfType <StatusCodeResult>();

            response.Should().BeEquivalentTo(new StatusCodeResult(StatusCodes.Status406NotAcceptable));
        }
        public static async Task GetByOdsCodeAsync_VerifyMethodIsCalledOnce_VerifiesMethod()
        {
            const string odsCode = "123";

            var odsRepositoryMock = new Mock <IOdsRepository>();

            odsRepositoryMock.Setup(r => r.GetBuyerOrganisationByOdsCodeAsync(It.IsAny <string>()))
            .ReturnsAsync((OdsOrganisation)null);

            using var controller = OdsControllerBuilder.Create()
                                   .WithOdsRepository(odsRepositoryMock.Object)
                                   .Build();

            await controller.GetByOdsCodeAsync(odsCode);

            odsRepositoryMock.Verify(r => r.GetBuyerOrganisationByOdsCodeAsync(odsCode));
        }
        public async Task GetByOdsCodeAsync_OrganisationExists_ReturnsActiveBuyerOrganisation()
        {
            var buyerOrganisation = OdsOrganisationBuilder.Create(1, true).Build();

            using var controller = OdsControllerBuilder
                                   .Create()
                                   .WithGetByOdsCode(buyerOrganisation)
                                   .Build();

            var response = await controller.GetByOdsCodeAsync(buyerOrganisation.OdsCode);

            response.Should().BeOfType <OkObjectResult>();

            var result = response as OkObjectResult;

            result.Value.Should().BeEquivalentTo(buyerOrganisation, options => options.Excluding(o => o.IsActive).Excluding(o => o.IsBuyerOrganisation));
        }
        public static async Task GetByOdsCodeAsync_OrganisationDoesNotExists_ReturnsOrganisationWithNullOrganisationId()
        {
            var buyerOrganisation = OdsOrganisationBuilder.Create(1, true).Build();

            using var controller = OdsControllerBuilder
                                   .Create()
                                   .WithGetByOdsCode(buyerOrganisation, null)
                                   .Build();

            var response = await controller.GetByOdsCodeAsync(buyerOrganisation.OdsCode);

            response.Should().BeOfType <OkObjectResult>();
            response.As <OkObjectResult>().Value.Should().BeEquivalentTo(
                new OdsOrganisationModel
            {
                OdsCode          = buyerOrganisation.OdsCode,
                OrganisationId   = null,
                OrganisationName = buyerOrganisation.OrganisationName,
                PrimaryRoleId    = buyerOrganisation.PrimaryRoleId,
            });
        }
 static async Task GetOrganisationByNullOdsCode()
 {
     using var controller = OdsControllerBuilder.Create().Build();
     await controller.GetByOdsCodeAsync(null);
 }