Beispiel #1
0
        public ActionResult Create([Bind(Include = "AssistanceID,assistanceDate,ClientID")] Assistance assistance)
        {
            if (ModelState.IsValid)
            {
                assistanceRepository.InsertAssistance(assistance);
                assistanceRepository.Save();
                return(RedirectToAction("Index"));
            }

            return(View(assistance));
        }
        public void Assistance_Edit_HttpPost()
        {
            var originalAssistance = assistances.FirstOrDefault();
            var originalDate       = assistances.FirstOrDefault().assistanceDate;

            Mock.Arrange(() => assistanceRepository.Save()).DoInstead(() => { originalAssistance.assistanceDate = DateTime.Now; });

            ActionResult actionResult = controller.Edit(newAssistance) as ActionResult;

            Assert.AreNotEqual(originalAssistance.assistanceDate, originalDate);
            Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult));
        }
Beispiel #3
0
        public ActionResult Access(string docNumber)
        {
            #region Validations
            int  documentNumber;
            bool parseResult = Int32.TryParse(docNumber, out documentNumber);

            if (!parseResult || docNumber.Length != 8)
            {
                ModelState.AddModelError("Format", "Debes ingresar un número de documento");
                return(View());
            }
            #endregion

            Client client = clientRepository.GetClients().Where(c => c.DocNumber == documentNumber && c.Role == Catalog.Roles.Client).FirstOrDefault();

            //var result = clientRepository.ListOfPayments(client);

            if (client == null || (client.Role != Catalog.Roles.Client))
            {
                //No se encontró un cliente con los datos ingresados o bien no es cliente, es admin o profesor
                ModelState.AddModelError("Format", "No se encontró ningún socio con el nro de documento ingresado");
                return(View());
            }
            else if (clientRepository.HasActivePayment(client))
            {
                //OK
                Assistance assistance = new Assistance {
                    assistanceDate = DateTime.Now, ClientID = client.ClientID
                };
                assistanceRepository.InsertAssistance(assistance);
                assistanceRepository.Save();
                ViewBag.IsEnabled = true;
            }
            else
            {
                ViewBag.IsEnabled = false;
                //No tiene abono activo
            }
            return(View());
        }
        public void Init()
        {
            #region Dummy Assistance List
            assistances = new List <Assistance>
            {
                new Assistance {
                    AssistanceID = 1, assistanceDate = new DateTime(2016, 01, 01), ClientID = 1
                },
                new Assistance {
                    AssistanceID = 2, assistanceDate = new DateTime(2015, 01, 01), ClientID = 1
                },
                new Assistance {
                    AssistanceID = 3, assistanceDate = new DateTime(2016, 02, 01), ClientID = 1
                },
                new Assistance {
                    AssistanceID = 4, assistanceDate = new DateTime(2016, 01, 01), ClientID = 2
                },
                new Assistance {
                    AssistanceID = 5, assistanceDate = new DateTime(2015, 01, 01), ClientID = 2
                },
                new Assistance {
                    AssistanceID = 6, assistanceDate = new DateTime(2016, 02, 01), ClientID = 2
                },
                new Assistance {
                    AssistanceID = 7, assistanceDate = new DateTime(2016, 01, 01), ClientID = 3
                },
                new Assistance {
                    AssistanceID = 8, assistanceDate = new DateTime(2015, 01, 01), ClientID = 3
                },
                new Assistance {
                    AssistanceID = 9, assistanceDate = new DateTime(2016, 02, 01), ClientID = 3
                },
                new Assistance {
                    AssistanceID = 10, assistanceDate = new DateTime(2015, 01, 01), ClientID = 4
                },
                new Assistance {
                    AssistanceID = 11, assistanceDate = new DateTime(2016, 02, 01), ClientID = 4
                },
                new Assistance {
                    AssistanceID = 12, assistanceDate = new DateTime(2015, 01, 01), ClientID = 5
                },
                new Assistance {
                    AssistanceID = 13, assistanceDate = new DateTime(2016, 02, 01), ClientID = 5
                },
                new Assistance {
                    AssistanceID = 14, assistanceDate = new DateTime(2016, 02, 01), ClientID = 6
                },
                new Assistance {
                    AssistanceID = 15, assistanceDate = new DateTime(2016, 02, 01), ClientID = 6
                },
                new Assistance {
                    AssistanceID = 16, assistanceDate = new DateTime(2016, 02, 01), ClientID = 6
                },
                new Assistance {
                    AssistanceID = 17, assistanceDate = new DateTime(2016, 02, 01), ClientID = 8
                },
                new Assistance {
                    AssistanceID = 18, assistanceDate = new DateTime(2016, 02, 01), ClientID = 8
                },
                new Assistance {
                    AssistanceID = 19, assistanceDate = new DateTime(2016, 02, 01), ClientID = 8
                },
                new Assistance {
                    AssistanceID = 20, assistanceDate = new DateTime(2016, 02, 01), ClientID = 8
                },
                new Assistance {
                    AssistanceID = 21, assistanceDate = new DateTime(2016, 02, 01), ClientID = 8
                },
                new Assistance {
                    AssistanceID = 22, assistanceDate = new DateTime(2016, 02, 01), ClientID = 7
                },
                new Assistance {
                    AssistanceID = 23, assistanceDate = new DateTime(2016, 02, 01), ClientID = 7
                },
                new Assistance {
                    AssistanceID = 24, assistanceDate = new DateTime(2016, 02, 01), ClientID = 7
                }
            };
            #endregion

            #region Dummy New Assistance
            newAssistance = new Assistance {
                AssistanceID = 25, assistanceDate = new DateTime(2016, 02, 01), ClientID = 7
            };
            #endregion


            #region Repositories
            assistanceRepository = Mock.Create <IAssistanceRepository>();
            #endregion

            #region JustMock Assistances Arrange
            Mock.Arrange(() => assistanceRepository.GetAssistances()).Returns(assistances);
            Mock.Arrange(() => assistanceRepository.GetAssistanceByID(ASSISTANCE_ID_TO_USE))
            .Returns(assistances.Where(a => a.AssistanceID == ASSISTANCE_ID_TO_USE).FirstOrDefault());
            Mock.Arrange(() => assistanceRepository.InsertAssistance(newAssistance))
            .DoInstead(() => assistances.Add(newAssistance))
            .MustBeCalled();
            Mock.Arrange(() => assistanceRepository.DeleteAssistance(ASSISTANCE_ID_TO_USE))
            .DoInstead(() => assistances.Remove(assistances.Where(a => a.AssistanceID == ASSISTANCE_ID_TO_USE).FirstOrDefault()));
            Mock.Arrange(() => assistanceRepository.Save()).DoNothing();
            #endregion

            #region Controller creation
            controller = new AssistancesController(assistanceRepository);
            #endregion
        }