Esempio n. 1
0
        public async Task TestDeleteCodeGoodData()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            CodeService  codeService = new CodeService(context);
            Apartment    apartment1  = new Apartment {
                Number = 1
            };
            Apartment apartment2 = new Apartment {
                Number = 2
            };
            await context.Apartments.AddAsync(apartment1);

            await context.Apartments.AddAsync(apartment2);

            RegistrationCode code1 = new RegistrationCode {
                Code = "code1", Apartment = apartment1
            };
            RegistrationCode code2 = new RegistrationCode {
                Code = "code2", Apartment = apartment2
            };
            await context.RegistrationCodes.AddAsync(code1);

            await context.RegistrationCodes.AddAsync(code2);

            await context.SaveChangesAsync();

            bool output = await codeService.DeleteCode(code1.Code);

            Assert.True(output);
            Assert.Single(context.RegistrationCodes.ToList());
            Assert.Equal("code2", context.RegistrationCodes.ToList()[0].Code);
        }
Esempio n. 2
0
        public async Task TestDeleteBadCode()
        {
            ACMDbContext context     = ACMDbContextInMemoryFactory.InitializeContext();
            CodeService  codeService = new CodeService(context);
            Apartment    apartment1  = new Apartment {
                Number = 1
            };
            Apartment apartment2 = new Apartment {
                Number = 2
            };
            await context.Apartments.AddAsync(apartment1);

            await context.Apartments.AddAsync(apartment2);

            RegistrationCode code1 = new RegistrationCode {
                Code = "code1", Apartment = apartment1
            };
            RegistrationCode code2 = new RegistrationCode {
                Code = "code2", Apartment = apartment2
            };
            await context.RegistrationCodes.AddAsync(code1);

            await context.RegistrationCodes.AddAsync(code2);

            await context.SaveChangesAsync();

            await Assert.ThrowsAsync <ACMException>(() => codeService.DeleteCode("not a real code"));
        }
Esempio n. 3
0
        public IActionResult DeleteCode(int id)
        {
            try
            {
                _codeService.DeleteCode(id);
                return(Ok());
            }
            catch (AuthenticationException)
            {
                return(Forbid());
            }
            catch (ServiceException ex)
            {
                return(BadRequest(ex.Message));
            }

            catch (Exception ex)
            {
                return(BadRequest(ex.StackTrace));
            }
        }