コード例 #1
0
        public async Task EditeAsyncWithDublicateNameShouldThrowArgumentException()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext         = new ApplicationDbContext(options);
            var cloudinary        = new Mock <ICloudinaryService>();
            var membersRepository = new EfDeletableEntityRepository <Member>(dbContext);
            var service           = new MembersService(membersRepository, cloudinary.Object);

            var photo = new Mock <IFormFile>();

            await service.CreateAsync("Lars Ulrich", photo.Object, "description", 2);

            var id = await service.CreateAsync("Kirk Hammett", photo.Object, "description", 2);

            var model = new MemberEditInputModel
            {
                FullName    = "Lars Ulrich",
                Photo       = photo.Object,
                Description = "description",
                GroupId     = 2,
            };

            await Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                await service.EditAsync(id, model);
            });
        }
コード例 #2
0
        public async Task CreateAsyncWithCorrectDataShouldThrowArgumentException()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext         = new ApplicationDbContext(options);
            var cloudinary        = new Mock <ICloudinaryService>();
            var membersRepository = new EfDeletableEntityRepository <Member>(dbContext);
            var service           = new MembersService(membersRepository, cloudinary.Object);

            var photo = new Mock <IFormFile>();

            await service.CreateAsync("Lars Ulrich", photo.Object, "description", 2);

            await Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                await service.CreateAsync("Lars Ulrich", photo.Object, "description", 2);
            });
        }
コード例 #3
0
        public async Task CreateAsyncWithCorrectDataShouldReturnCorrectResult()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext         = new ApplicationDbContext(options);
            var cloudinary        = new Mock <ICloudinaryService>();
            var membersRepository = new EfDeletableEntityRepository <Member>(dbContext);
            var service           = new MembersService(membersRepository, cloudinary.Object);

            var photo  = new Mock <IFormFile>();
            var actual = await service.CreateAsync("Kirk Hammett", photo.Object, "description", 2);

            var expected = 1;

            Assert.Equal(expected, actual);
        }
コード例 #4
0
        public async Task <IActionResult> RegisterPrivate(MembersRegisterPrivateVM membersRegisterPrivateVM)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.BackButton = true;
                return(View(membersRegisterPrivateVM));
            }

            var isAdded = await membersService.CreateAsync(membersRegisterPrivateVM);

            if (!isAdded)
            {
                ViewBag.BackButton = true;
                return(View(membersRegisterPrivateVM));
            }

            return(RedirectToAction(nameof(Index)));
        }
コード例 #5
0
        public async Task EditAsyncWithCorrectDataShouldReturnCorrectResult()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext         = new ApplicationDbContext(options);
            var cloudinary        = new Mock <ICloudinaryService>();
            var membersRepository = new EfDeletableEntityRepository <Member>(dbContext);
            var service           = new MembersService(membersRepository, cloudinary.Object);

            var photo = new Mock <IFormFile>();
            var id    = await service.CreateAsync("Kirk Hammett", photo.Object, "description", 2);

            var model = new MemberEditInputModel
            {
                FullName    = "Kirk Hammett",
                Photo       = photo.Object,
                Description = "Other",
                GroupId     = 1,
            };

            Assert.True(await service.EditAsync(id, model));
        }