Esempio n. 1
0
        public async Task CombatEpic_0004_AnyMutant_ReturnsVictoryPhrase()
        {
            // arrange
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When(HttpMethod.Get, "https://quotes.rest/qod")
            .Respond("application/json", @"{
  'contents': {
    'quotes': [
      {
        'quote': 'The answer is 42'
      }
    ]
  }
}");
            var httpClientfactory = Substitute.For <IHttpClientFactory>();

            httpClientfactory.CreateClient(Arg.Any <string>()).Returns(mockHttp.ToHttpClient());
            var currentfactory = factory
                                 .WithWebHostBuilder(builder => builder.ConfigureTestServices(
                                                         services => services.AddSingleton(httpClientfactory)));

            var client = currentfactory.CreateClient();

            // act
            var response = await client.GetAsync("api/combat/epic?attacker=Magneto&defender=Xavier");

            // assert
            response.EnsureSuccessStatusCode();
            var result = await response.Content.ReadAsAsync <CombatResult>();

            Assert.Equal("The answer is 42", result.VictoryPhrase);
        }
Esempio n. 2
0
        public EngineRoutesSteps(TestWebApplicationFactory factory)

        {
            var engine = new MyEngine
            {
                //Id = "6048d0b57757e1f98eb48273",
                Id = new ObjectId(timestamp: 1617721631, machine: 7894647, pid: 13311, increment: 5403081),
                /*, creationTime: "2021-04-06T15:07:11Z"*/
                Code       = 16,
                Name       = "Beuate",
                IsEnable   = true,
                SearchText = "string",
                Scopes     = new List <Scope> {
                    new Scope {
                        ScopeId = 2, Name = "string", Order = 0, IsEnable = true
                    }
                },
                InputFields = new List <InputField> {
                    new InputField {
                        InputId = 1, IsEnable = true, IsMandatory = true, Label = "string", Order = 0, Type = "string", Parameters = new List <Parameter> {
                            new Parameter {
                                ScopeParameterId = 1, ExternalCodeId = 0, Order = 0, Label = "string"
                            }
                        }
                    }
                },
                BackGroundImages = new List <BackGroundImage> {
                    new BackGroundImage {
                        Alt = "string", IsEnable = true, OpenInNewTab = true, Order = 0, UrlImageDesktop = "string", UrlLinkDesktop = "string", UrlImageMobile = "string", UrlLinkMobile = "string"
                    }
                },
                Logo = new List <Logo> {
                    new Logo {
                        UrlImageDesktop = "string", UrlLinkDesktop = "string", UrlImageMobile = "string", UrlLinkMobile = "string", Alt = "string", IsEnable = true, OpenInNewTab = true
                    }
                },
                MarketingText = new List <MarketingText> {
                    new MarketingText {
                        IsEnable = true, Text = "string"
                    }
                }
            };

            _engineReadRepository.Setup(r => r.CreateEngine(engine)).Returns(_inMemoryEngineReadRepository.CreateEngine(engine));
            _engineReadRepository.Setup(r => r.GetEngineById(It.IsIn(16))).Returns(_inMemoryEngineReadRepository.GetEngineById(16));
            _engineReadRepository.Setup(r => r.GetEngines()).Returns(_inMemoryEngineReadRepository.GetEngines());
            _engineReadRepository.Setup(r => r.DeleteEngine(It.IsIn(16))).Returns(_inMemoryEngineReadRepository.DeleteEngine(16));
            _engineReadRepository.Setup(r => r.UpdateEngine(It.IsIn(16), engine)).Returns(_inMemoryEngineReadRepository.UpdateEngine(16, engine));

            _factory = factory.WithWebHostBuilder(
                builder => builder.ConfigureTestServices(
                    services =>
            {
                services.AddScoped(ser => _engineReadRepository);
                services.AddScoped(ser => _engineReadRepository.Object);
            }));


            _client = _factory.CreateClient();
        }
Esempio n. 3
0
        public async Task Find_Success()
        {
            // Arrange
            var client = _factory.WithWebHostBuilder(builder => builder.ConfigureTestServices(services =>
            {
                var identityClientMock = new Mock <IdentityService.IdentityServiceClient>();
                identityClientMock.Setup(s => s.GetUsersByIdsAsync(It.IsAny <GetUsersByIdsRequest>(),
                                                                   null, null, It.IsAny <CancellationToken>()))
                .Returns(GrpcTestCalls.AsyncUnaryCall(new GetUsersByIdsResponse
                {
                    Users = { new GetUsersByIdsResponse.Types.User {
                                  Id = MasterData.CurrentUserId, Email = "*****@*****.**", UserName = "******"
                              } }
                }));

                services.AddSingleton(identityClientMock.Object);
            })).CreateClient();

            // Act
            var response = await client.GetAsync(Uri + "/offset");

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var result = await response.Content.ReadAsAsync <OffsetPaged <ReviewDto> >();

            result.Data.Should().NotBeNullOrEmpty();
        }
Esempio n. 4
0
        public void GivenIAmAEmployerUsingTheReservationService()
        {
            var testData = new TestData
            {
                AccountLegalEntity = new AccountLegalEntity
                {
                    AccountId                        = TestDataValues.NonLevyAccountId,
                    AccountLegalEntityId             = TestDataValues.NonLevyAccountLegalEntityId,
                    AccountLegalEntityPublicHashedId = TestDataValues.NonLevyHashedAccountLegalEntityId,
                    AccountLegalEntityName           = "Test Legal Entity",
                    IsLevy        = false,
                    LegalEntityId = 1
                }
            };

            _factory = new TestWebApplicationFactory("employer");
            _client  = _factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureServices(collection =>
                                          collection.ConfigureTestServiceCollection(
                                              _factory.ConfigurationRoot, testData));
                builder.ConfigureTestServices(services =>
                {
                    services.AddAuthentication("IntegrationTest")
                    .AddScheme <TestAuthenticationSchemeOptions, TestAuthenticationHandler>(
                        "IntegrationTest", options => { options.EmployerAccountId = TestDataValues.NonLevyHashedAccountId; });
                });
            }).CreateClient();
            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("IntegrationTest");
        }
Esempio n. 5
0
        private HttpClient GetAdminClient()
        {
            var client = TestWebApplicationFactory
                         .WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.RemoveRegisteredType(typeof(HttpContextAccessor));
                    var context = new AdminHttpContextStub();
                    services.AddSingleton <IHttpContextAccessor, AdminHttpContextStub>(s => context);
                });
            }
                                             )
                         .CreateClient();

            return(client);
        }
        public EstimateTaskControllerTest(TestWebApplicationFactory <DocumentsKM.Startup> factory)
        {
            _httpClient = factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddSingleton <IPolicyEvaluator, FakePolicyEvaluator>();
                });
            }).CreateClient();

            _authHttpClient = factory.CreateClient();
        }
Esempio n. 7
0
        public BaseServiceTest(TestWebApplicationFactory <Startup> factory, ETestType type = ETestType.Empty)
        {
            if (factory is null)
            {
                return;
            }
            _factory = factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddMoqRepository(type);
                });
            });

            _serviceScope = _factory.Services.CreateScope();
        }
Esempio n. 8
0
        public void Scenario_GetMutant_0003_Wolverine(DbContextOptions <MutantsContext> options, WebApplicationFactory <TestStartup> currentfactory,
                                                      HttpResponseMessage response)
        {
            $"Given database".x(() =>
            {
                options = new DbContextOptionsBuilder <MutantsContext>()
                          .UseInMemoryDatabase(databaseName: nameof(Scenario_GetMutant_0003_Wolverine))
                          .Options;
            });

            var mutant = new Mutant
            {
                Name       = "Wolverine",
                RealName   = "Logan",
                Superpower = "Invulnerability, Claws"
            };

            $"And the mutant {mutant}".x(() =>
            {
                using (var context = new MutantsContext(options))
                {
                    context.Mutants.Add(mutant);
                    context.SaveChanges();
                }
                currentfactory = factory
                                 .WithWebHostBuilder(builder => builder.ConfigureTestServices(
                                                         services => services.AddSingleton(new MutantsContext(options))));
            });

            $"When get mutant by name Wolverine"
            .x(async() => response = await currentfactory.CreateClient().GetAsync("api/mutants/Wolverine"));

            "Then returns the mutant Wolverine (Logan): Invulnerability, Claws"
            .x(async() =>
            {
                response.EnsureSuccessStatusCode();
                var result = await response.Content.ReadAsAsync <Mutant>();
                Assert.Equal("Wolverine", result.Name);
                Assert.Equal("Logan", result.RealName);
                Assert.Equal("Invulnerability, Claws", result.Superpower);
            });
        }
Esempio n. 9
0
        public BaseControllerTest(TestWebApplicationFactory <Startup> factory, ETestType type = ETestType.Empty)
        {
            if (factory is null)
            {
                return;
            }
            _factory = factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddMoqRepository(type);
                    services.AddMoqService(type);
                });
            });

            GetClient = _factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false,
            });

            _serviceScope = _factory.Services.CreateScope();
        }
Esempio n. 10
0
 internal WebApplicationFactory <Startup> RegisterMockComponents(Action <IServiceCollection> serviceCollection)
 {
     return(Factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(serviceCollection); }));
 }