Пример #1
0
        public async Task Open_CallsOpenOnPackService()
        {
            var userId = Guid.NewGuid();
            var packId = Guid.NewGuid();

            var mockPackService = new Mock <IPackService>();

            var controller = new PacksController(mockPackService.Object);

            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.NameIdentifier, userId.ToString())
            };
            var identity        = new ClaimsIdentity(claims, "TestAuthType");
            var claimsPrincipal = new ClaimsPrincipal(identity);

            var contextStub = new DefaultHttpContext
            {
                User = claimsPrincipal
            };

            controller.ControllerContext = new ControllerContext
            {
                HttpContext = contextStub
            };

            //Act
            var result = await controller.Open(packId);

            //Assert
            mockPackService.Verify(x => x.Open(packId, userId.ToString()), Times.Once);
        }
        public void BeforeTest()
        {
            var builder = new DbContextOptionsBuilder <PackContext>();

            builder.EnableSensitiveDataLogging();
            builder.UseInMemoryDatabase("testpack");

            var context    = new PackContext(builder.Options);
            var repository = new PackRepository(context);

            this.controller = new(
                Mock.Of <ILogger <PacksController> >(),
                repository);
            Assert.IsNotNull(this.controller);
        }