public void TestInitialize() { webApiMapper = new WebApiMapper(); typeReq = new TypeReqEntity { Id = 1234, Name = "Taxi - Acoso", TopicEntityId = 1, AdditionalFields = new List <AdditionalFieldEntity> { new AdditionalFieldEntity() } }; typeReqModelOut = new TypeReqModelOut { Id = 1234, Name = "Taxi - Acoso", }; typeReqModelIn = new TypeReqModelIn { Id = 1234, Name = "Taxi - Acoso", }; additionalField = new AdditionalFieldEntity { Id = 1234, Name = "Matrícula", Type = AdditionalFieldType.TEXTO.ToString(), Range = "Radio Taxi - Taxi aeropuerto - Fono Taxi", TypeReqEntityId = 1 }; typeReqLogicMock = new Mock <ITypeReqLogic>(); typeReqController = new TypeReqController(typeReqLogicMock.Object, webApiMapper); }
public void TestInitialize() { xmlImporter = new XmlImporter(); firstArea = new AreaEntity { Name = "Area_One", }; secondArea = new AreaEntity { Name = "Area_Two", }; firstTopic = new TopicEntity { Name = "Topic_One", AreaEntityId = 2, }; secondTopic = new TopicEntity { Name = "Topic_Two", AreaEntityId = 2, }; firstTypeReq = new TypeReqEntity { Name = "TypeReq_One", TopicEntityId = 1, }; secondTypeReq = new TypeReqEntity { Name = "TypeReq_Two", TopicEntityId = 2, }; }
public void TestInitialize() { testTypeReqEntity = new TypeReqEntity { Id = 1234, Name = "Taxi - Acoso", AdditionalFields = new List <AdditionalFieldEntity>() }; testAFEntity = new AdditionalFieldEntity { Id = 1234, Name = "Matrícula", Type = "TEXTO", Range = "Radio Taxi-Taxi aeropuerto-Fono Taxi", TypeReqEntityId = 1 }; typeReqRepository = new Mock <IRepository <TypeReqEntity> >(MockBehavior.Strict); topicRepository = new Mock <IRepository <TopicEntity> >(MockBehavior.Strict); aFRepository = new Mock <IRepository <AdditionalFieldEntity> >(MockBehavior.Strict); unitOfWork = new Mock <IUnitOfWork>(); unitOfWork.Setup(r => r.TypeReqRepository).Returns(typeReqRepository.Object); unitOfWork.Setup(r => r.TopicRepository).Returns(topicRepository.Object); unitOfWork.Setup(r => r.AdditionalFieldRepository).Returns(aFRepository.Object); typeReqLogic = new TypeReqLogic(unitOfWork.Object); }
public ICollection <TypeReqEntity> GetTypeReqs(ICollection <Parameter> parameters) { try { var pathJsonFile = parameters.OfType <Parameter>().FirstOrDefault().Value; var jsonText = File.ReadAllText(pathJsonFile); JObject dataIn = JObject.Parse(jsonText); IList <JToken> results = dataIn["TypeReqEntity"].Children().ToList(); var result = new List <TypeReqEntity>(); foreach (JToken typeReqIn in results) { TypeReqEntity newType = new TypeReqEntity(); newType.Name = typeReqIn.ToObject <TypeReqEntity>().Name; newType.TopicEntityId = typeReqIn.ToObject <TypeReqEntity>().TopicEntityId; result.Add(newType); } return(result); } catch (ArgumentException) { throw new ArgumentException("Path invalido"); } }
public TypeReqEntity GetByName(string name) { if (!TypeNameExists(name)) { throw new ArgumentException($"Type with name: {name} doesn't exist"); } TypeReqEntity ret = unitOfWork.TypeReqRepository.FirstOrDefault(u => u.Name == name && !u.IsDeleted); return(ret); }
public TypeReqEntity GetById(int id) { if (!TypeExists(id)) { throw new ArgumentException($"Type with Id: {id} doesn't exist"); } TypeReqEntity ret = unitOfWork.TypeReqRepository.FirstOrDefault(u => u.Id == id && !u.IsDeleted); return(ret); }
private void getFathersNames(RequestEntity request) { TypeReqEntity typeReq = unitOfWork.TypeReqRepository.FirstOrDefault(t => t.Id == request.RequestTypeEntityId); request.TypeName = typeReq.Name; TopicEntity topic = unitOfWork.TopicRepository.FirstOrDefault(t => t.Id == typeReq.TopicEntityId); request.TopicName = topic.Name; AreaEntity area = unitOfWork.AreaRepository.FirstOrDefault(a => a.Id == topic.AreaEntityId); request.AreaName = area.Name; }
public void Update(TypeReqEntity tr) { if (!TypeExists(tr.Id)) { throw new ArgumentException($"Type with id: {tr.Id} doesn't exist"); } TypeReqEntity trToUpdate = unitOfWork.TypeReqRepository.FirstOrDefault(u => u.Id == tr.Id && !tr.IsDeleted); trToUpdate.Name = tr.Name; if (tr.AdditionalFields == null) { tr.AdditionalFields = new List <AdditionalFieldEntity>(); } unitOfWork.TypeReqRepository.Update(trToUpdate); unitOfWork.Save(); }
public IEnumerable <AdditionalFieldEntity> GetAdditionalFields(int typeId) { if (!TypeExists(typeId)) { throw new ArgumentException($"Type with id: {typeId} doesn't exist"); } List <AdditionalFieldEntity> result = new List <AdditionalFieldEntity>(); IEnumerable <AdditionalFieldEntity> addFEntities = unitOfWork.AdditionalFieldRepository.GetAll().Where(add => !add.IsDeleted); foreach (var entity in addFEntities) { TypeReqEntity typeReqEntity = unitOfWork.TypeReqRepository.FirstOrDefault(u => u.Id.Equals(entity.TypeReqEntityId) && !u.IsDeleted); if (typeReqEntity != null && typeId == typeReqEntity.Id) { result.Add(entity); } } return(result); }
public void TestInitialize() { testTypeReqEntity = new TypeReqEntity { Id = 1234, Name = "Taxi - Acoso", AdditionalFields = new AdditionalFieldEntity[] { new AdditionalFieldEntity() } }; testRequestEntity = new RequestEntity { Detail = "Un contenedor roto en la esquina de Av. Italia y Bolivia", ApplicantName = "Federico Jacobo", Mail = "*****@*****.**", Phone = "098555666", RequestTypeEntityId = 1, TypeName = "Contenedor roto", Status = "CREADA" }; testUserEntity = new UserEntity { CompleteName = "Nahuel Kleiman", Mail = "*****@*****.**", Password = "******", Requests = new List <RequestEntity>() }; requestRepository = new Mock <IRepository <RequestEntity> >(MockBehavior.Strict); typeReqRepository = new Mock <IRepository <TypeReqEntity> >(MockBehavior.Strict); userRepository = new Mock <IRepository <UserEntity> >(MockBehavior.Strict); addFRepository = new Mock <IRepository <AdditionalFieldEntity> >(MockBehavior.Strict); topicRepository = new Mock <IRepository <TopicEntity> >(MockBehavior.Strict); areaRepository = new Mock <IRepository <AreaEntity> >(MockBehavior.Strict); unitOfWork = new Mock <IUnitOfWork>(); unitOfWork.Setup(u => u.RequestRepository).Returns(requestRepository.Object); unitOfWork.Setup(r => r.TypeReqRepository).Returns(typeReqRepository.Object); unitOfWork.Setup(r => r.UserRepository).Returns(userRepository.Object); unitOfWork.Setup(r => r.AdditionalFieldRepository).Returns(addFRepository.Object); unitOfWork.Setup(r => r.TopicRepository).Returns(topicRepository.Object); unitOfWork.Setup(r => r.AreaRepository).Returns(areaRepository.Object); requestLogic = new RequestLogic(unitOfWork.Object); }
public void TestInitialize() { area = new AreaEntity { Id = 1, Name = "Limpieza", Topics = new List <TopicEntity>() }; topic = new TopicEntity { Id = 1, Name = "Contenedores de basura", AreaEntityId = 1, RequestTypes = new List <TypeReqEntity>() }; type = new TypeReqEntity { Id = 1, Name = "Roto", AdditionalFields = new List <AdditionalFieldEntity>(), TopicEntityId = 1 }; unitOfWork = new Mock <IUnitOfWork>(); areaRepository = new Mock <IRepository <AreaEntity> >(); topicRepository = new Mock <IRepository <TopicEntity> >(); typeRepository = new Mock <IRepository <TypeReqEntity> >(); unitOfWork.Setup(u => u.AreaRepository).Returns(areaRepository.Object); unitOfWork.Setup(u => u.TopicRepository).Returns(topicRepository.Object); unitOfWork.Setup(u => u.TypeReqRepository).Returns(typeRepository.Object); var configuration = new Mock <IConfiguration>(); configuration.Setup(c => c["DataImport:Path"]).Returns(".\\Assemblies\\DataImport"); areaLogic = new AreaLogic(unitOfWork.Object); topicLogic = new TopicLogic(unitOfWork.Object); typeLogic = new TypeReqLogic(unitOfWork.Object); importLogic = new ImportLogic(unitOfWork.Object, configuration.Object, areaLogic, topicLogic, typeLogic); }
public int Add(TypeReqEntity tr) { if (TypeExists(tr.Id)) { throw new ArgumentException($"Type with id: {tr.Id} already exist"); } if (!TopicExists(tr)) { throw new ArgumentException($"Topic does not exist"); } /*if(tr.TopicEntityId<1 || tr.TopicEntityId > 18) * throw new ArgumentException($"Topic with id: {tr.TopicEntityId} does not exist");*/ if (TypeNameExistsInTopic(tr)) { throw new ArgumentException($"There is already a type with name {tr.Name} in the topic with id: {tr.TopicEntityId}"); } unitOfWork.TypeReqRepository.Add(tr); unitOfWork.Save(); return(this.GetByName(tr.Name).Id); }
public void Delete(int id) { if (!unitOfWork.TypeReqRepository.Exists(a => !a.IsDeleted && a.Id == id)) { throw new ArgumentException($"Type with id: {id} doesn't exist"); } TypeReqEntity typeReqEntity = unitOfWork.TypeReqRepository.FirstOrDefault(tr => !tr.IsDeleted && tr.Id == id); typeReqEntity.IsDeleted = true; unitOfWork.TypeReqRepository.Update(typeReqEntity); List <AdditionalFieldEntity> aF = GetAdditionalFieldFromType(typeReqEntity.Id); foreach (var a in aF) { a.IsDeleted = true; unitOfWork.AdditionalFieldRepository.Update(a); } unitOfWork.Save(); }
public void Put_Expects_Ok() { TypeReqEntity updatedTypeReq = typeReq; updatedTypeReq.Name = "new name"; typeReqModelIn.Name = "new name"; typeReqLogicMock.Setup(a => a.Update(typeReq)); typeReqLogicMock.Setup(a => a.GetById(typeReq.Id)).Returns(updatedTypeReq); var result = typeReqController.Put(typeReq.Id, typeReqModelIn); var updatedResult = result as CreatedResult; var modelOut = updatedResult.Value as TypeReqModelOut; typeReqLogicMock.VerifyAll(); Assert.IsNotNull(result); Assert.IsNotNull(updatedResult); Assert.AreEqual(modelOut.Name, typeReqModelIn.Name); Assert.AreEqual(201, updatedResult.StatusCode); }
public void UpdateTypeReqTest() { var testTypeReqEntityUpd = new TypeReqEntity { Id = 1234, Name = "Tax", AdditionalFields = new AdditionalFieldEntity[] { new AdditionalFieldEntity() } }; typeReqRepository.Setup(u => u.Exists(It.IsAny <Expression <Func <TypeReqEntity, bool> > >())).Returns(true); typeReqRepository.Setup(u => u.FirstOrDefault(It.IsAny <Expression <Func <TypeReqEntity, bool> > >())).Returns(testTypeReqEntityUpd); typeReqRepository.Setup(u => u.Update(It.IsAny <TypeReqEntity>())).Verifiable(); typeReqRepository.Setup(u => u.FirstOrDefault(It.IsAny <Expression <Func <TypeReqEntity, bool> > >())).Returns(testTypeReqEntityUpd); unitOfWork.Setup(r => r.Save()); typeReqLogic.Update(testTypeReqEntity); var result = typeReqLogic.GetById(testTypeReqEntityUpd.Id); typeReqRepository.VerifyAll(); Assert.IsNotNull(result); Assert.AreEqual(testTypeReqEntityUpd.Name, result.Name); }
public ICollection <TypeReqEntity> GetTypeReqs(ICollection <Parameter> parameters) { try { var pathXmlFile = parameters.OfType <Parameter>().FirstOrDefault().Value; XmlDocument doc = new XmlDocument(); doc.Load(pathXmlFile); var result = new List <TypeReqEntity>(); XmlNode node = doc.DocumentElement.SelectSingleNode("Types"); foreach (XmlNode typeNode in node.ChildNodes) { TypeReqEntity newType = new TypeReqEntity(); foreach (XmlNode dataNode in typeNode.ChildNodes) { if (dataNode.Name.Equals("Name")) { newType.Name = dataNode.InnerText; } else if (dataNode.Name.Equals("TopicEntityId")) { int id = 0; Int32.TryParse(dataNode.InnerText, out id); newType.TopicEntityId = id; } } result.Add(newType); } return(result); } catch (ArgumentException) { throw new ArgumentException("Path Invalido"); } }
public void TestInitialize() { var options = new DbContextOptionsBuilder <Context>().UseInMemoryDatabase(databaseName: "TestDatabase").Options; context = new Context(options); repository = new Repository <RequestEntity>(context); typeReqEntity = new TypeReqEntity { Id = 1, Name = "Contenedor roto", AdditionalFields = new List <AdditionalFieldEntity>(), TopicEntityId = 2 }; requestEntity = new RequestEntity { Id = 1, Detail = "Contenedor de basura roto", ApplicantName = "Nahuel Kleiman", Mail = "*****@*****.**", Phone = "099565656", RequestTypeEntityId = 3, Status = "ACEPTADA" }; }
private bool TypeNameExistsInTopic(TypeReqEntity tr) { return(unitOfWork.TypeReqRepository.Exists(a => a.Name == tr.Name && !a.IsDeleted && a.TopicEntityId == tr.TopicEntityId)); }
private bool TopicExists(TypeReqEntity tr) { return(this.unitOfWork.TopicRepository.Exists(t => t.Id == tr.TopicEntityId)); }