Beispiel #1
0
        public IActionResult Post([FromBody] RegisterationInfo registerationInfo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            service.Save(registerationInfo);
            return(Ok());
        }
Beispiel #2
0
        public IActionResult Register([FromBody] RegisterationInfo registerationInfo)
        {
            var authMgr = new AuthManager(_context);
            var status  = authMgr.RegisterForNotification(registerationInfo);

            return(Ok(new
            {
                status
            }));
        }
        public void Given_ValidUserInfo_UserIsSaved()
        {
            var fileWriterService = Substitute.For <IFileWriterService>();
            var model             = new RegisterationInfo();
            var service           = new RegisterationService(fileWriterService);

            service.Save(model);

            fileWriterService.Received().Write(model.ToString());
        }
        public void Post_Method_GivenValidInput_Expect_ValidMessage()
        {
            var service           = NSubstitute.Substitute.For <IRegisterationService>();
            var controller        = new RegisterController(service);
            var registerationInfo = new RegisterationInfo();

            var result = controller.Post(registerationInfo);

            service.Received().Save(Arg.Any <RegisterationInfo>());
            result.GetType().ShouldBe(typeof(OkResult));
        }
Beispiel #5
0
        public void Valiedate_Model_Given_Valid_Model_ExpectNoValidationErrors()
        {
            var model = new RegisterationInfo();

            model.BankStateBranchCode = "123456";
            model.AccountNumber       = "11112222";
            model.AccountName         = "Test";
            model.Reference           = "test";
            model.Amount = 40m;

            var results = ValidateModel(model);

            results.Count.ShouldBe(0);
        }
Beispiel #6
0
 public bool RegisterForNotification(RegisterationInfo registerationInfo)
 {
     try
     {
         var user = _context.Users.Select(item => item).Where(item => item.Id.ToString() == registerationInfo.UserId).FirstOrDefault();
         user.NotificationRegId = registerationInfo.RegistrationId;
         _context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #7
0
        public void ValidateModel_Given_BSB_IsNull_ExpectBsbRequiredError()
        {
            var model = new RegisterationInfo();

            model.AccountNumber = "11112222";
            model.AccountName   = "Test";
            model.Reference     = "test";
            model.Amount        = 40m;

            var results = ValidateModel(model);

            results.Count.ShouldBe(1);
            results.First().ErrorMessage.ShouldBe("Please enter BSB Number.");
            results.First().MemberNames.First().ShouldBe(nameof(RegisterationInfo.BankStateBranchCode));
        }
        public void Post_Method_GivenInvalidInput_Expect_BadRequestAsResult()
        {
            var service           = NSubstitute.Substitute.For <IRegisterationService>();
            var controller        = new RegisterController(service);
            var registerationInfo = new RegisterationInfo();

            controller.ModelState.AddModelError(nameof(RegisterationInfo.AccountName), "fakeError");
            var result = controller.Post(registerationInfo);

            service.DidNotReceive().Save(Arg.Any <RegisterationInfo>());
            result.GetType().ShouldBe(typeof(BadRequestObjectResult));
            var badResult = (BadRequestObjectResult)result;

            badResult.Value.GetType().ShouldBe(typeof(SerializableError));
        }
Beispiel #9
0
        public void ValidateModel_Given_AccountNo_IsNull_ExpectAccountNumberRequiredError()
        {
            var model = new RegisterationInfo
            {
                BankStateBranchCode = "123456",
                AccountName         = "Test",
                Reference           = "test",
                Amount = 40m
            };

            var results = ValidateModel(model);

            results.Count.ShouldBe(1);
            results.Last().ErrorMessage.ShouldBe("Please enter account number.");
            results.Last().MemberNames.First().ShouldBe(nameof(RegisterationInfo.AccountNumber));
        }
Beispiel #10
0
        public void ValidateModel_Given_BSB_HasInValid_ExpectBsbRequiredError()
        {
            var model = new RegisterationInfo
            {
                BankStateBranchCode = "12346",
                AccountNumber       = "11112222",
                AccountName         = "Test",
                Reference           = "test",
                Amount = 40m
            };

            var results = ValidateModel(model);

            results.Count.ShouldBe(1);
            results.First().ErrorMessage.ShouldBe("The BSB number is invalid. Minimum 6 number is required.");
            results.First().MemberNames.First().ShouldBe(nameof(RegisterationInfo.BankStateBranchCode));
        }
 public void Save(RegisterationInfo model)
 {
     fileWriterService.Write(model.ToString());
 }