Exemple #1
0
        public async Task TestCreateInvalidUser()
        {
            ACMDbContext context   = ACMDbContextInMemoryFactory.InitializeContext();
            IPService    iPService = new IPService(context);
            ACMUser      user      = new ACMUser {
                UserName = "******", FullName = "gosho"
            };
            await context.Users.AddAsync(user);

            await context.SaveChangesAsync();

            IpDTO model = new IpDTO(null, "123.123.123...");
            await Assert.ThrowsAsync <ACMException>(() => iPService.Create(model));
        }
Exemple #2
0
        public async Task <string> Create(IpDTO ipViewModel)
        {
            if (ipViewModel.User == null)
            {
                throw new ACMException();
            }
            IP iP = new IP {
                User = ipViewModel.User, IpString = ipViewModel.Ip
            };
            await context.IPs.AddAsync(iP);

            await context.SaveChangesAsync();

            return(iP.Id);
        }
Exemple #3
0
        public async Task TestCreateGoodData()
        {
            ACMDbContext context   = ACMDbContextInMemoryFactory.InitializeContext();
            IPService    iPService = new IPService(context);
            ACMUser      user      = new ACMUser {
                UserName = "******", FullName = "gosho"
            };
            await context.Users.AddAsync(user);

            await context.SaveChangesAsync();

            IpDTO  model  = new IpDTO(user, "123.123.123...");
            string output = await iPService.Create(model);

            Assert.Single(context.IPs.ToList());
            Assert.True(context.IPs.Any(x => x.Id == output));
            Assert.Equal("*****@*****.**", context.IPs.FirstOrDefault().User.UserName);
            Assert.Equal("123.123.123...", context.IPs.FirstOrDefault().IpString);
        }