Ejemplo n.º 1
0
        public void RelacionarInterpretesACancion_SinInterpretes_Falla()
        {
            var entrada = new RelacionarInterpretesACancionEntrada
            {
                CancionId   = 5,
                Interpretes = null,
                Accion      = RelacionarInterpretesACancionEntrada.Acciones.Agregar,
            };

            var salida = _gestorDominio.RelacionarInterpretesACancion(entrada);

            Assert.IsTrue(salida == SalidaBase.Resultados.Fallo);
            Assert.AreEqual(Cadenas.album_falta_interprete, salida.Mensaje);
        }
Ejemplo n.º 2
0
        public RelacionarInterpretesACancionSalida RelacionarInterpretesACancion(
            RelacionarInterpretesACancionEntrada entrada)
        {
            var salida = new RelacionarInterpretesACancionSalida();

            var cancion = _gestorPersistencia.TraerCancion(entrada.CancionId);

            if (cancion == null)
            {
                return(SalidaBase.Fallo(salida, string.Format(Cadenas.cancion_id_no_encontrado, entrada.CancionId)));
            }

            if (cancion.AlbumId != null)
            {
                return(SalidaBase.Fallo(salida, string.Format(Cadenas.cancion_asociada_a_album, cancion.AlbumId)));
            }

            if (entrada.Interpretes == null || entrada.Interpretes.Count == 0)
            {
                return(SalidaBase.Fallo(salida, Cadenas.album_falta_interprete));
            }

            int interpreteError = int.MinValue;
            var interpretes     = TraerInterpretes(entrada.Interpretes, (noEncontrado => interpreteError = noEncontrado));

            if (interpreteError != int.MinValue)
            {
                return(SalidaBase.Fallo(salida, string.Format(Cadenas.interprete_id_no_encontrado, interpreteError)));
            }

            if (entrada.Accion == RelacionarInterpretesACancionEntrada.Acciones.Agregar)
            {
                var relaciones = interpretes.Select(i => _gestorPersistencia.TraerCancionInterprete(cancion.Id, i.Id));
                foreach (var relacion in relaciones)
                {
                    _gestorPersistencia.Guardar(relacion);
                }
            }
            else if (entrada.Accion == RelacionarInterpretesACancionEntrada.Acciones.Eliminar)
            {
                var relaciones = interpretes.Select(i => _gestorPersistencia.TraerCancionInterprete(cancion.Id, i.Id));
                foreach (var relacion in relaciones)
                {
                    _gestorPersistencia.EliminarCancionInterprete(relacion.InterpreteId, relacion.CancionId);
                }
            }

            return(SalidaBase.Exito(salida));
        }
Ejemplo n.º 3
0
        public void RelacionarInterpretesACancion_TodoNormal_Funciona()
        {
            var entrada = new RelacionarInterpretesACancionEntrada
            {
                CancionId   = 5,
                Interpretes = new List <int> {
                    2, 3
                },
                Accion = RelacionarInterpretesACancionEntrada.Acciones.Agregar,
            };

            var salida = _gestorDominio.RelacionarInterpretesACancion(entrada);

            Assert.IsTrue(salida == SalidaBase.Resultados.Exito);
        }
Ejemplo n.º 4
0
        public void RelacionarInterpretesACancion_InterpretesNoExisten_Falla()
        {
            var entrada = new RelacionarInterpretesACancionEntrada
            {
                CancionId   = 5,
                Interpretes = new List <int> {
                    10000000
                },
                Accion = RelacionarInterpretesACancionEntrada.Acciones.Agregar,
            };

            var salida = _gestorDominio.RelacionarInterpretesACancion(entrada);

            Assert.IsTrue(salida == SalidaBase.Resultados.Fallo);
            Assert.AreEqual(string.Format(Cadenas.interprete_id_no_encontrado, 10000000), salida.Mensaje);
        }
Ejemplo n.º 5
0
        public void RelacionarInterpretesACancion_CancionAsociadaAAlbum_Falla()
        {
            var entrada = new RelacionarInterpretesACancionEntrada
            {
                CancionId   = 1,
                Interpretes = new List <int> {
                    1
                },
                Accion = RelacionarInterpretesACancionEntrada.Acciones.Agregar,
            };

            var salida = _gestorDominio.RelacionarInterpretesACancion(entrada);

            Assert.IsTrue(salida == SalidaBase.Resultados.Fallo);
            Assert.AreEqual(string.Format(Cadenas.cancion_asociada_a_album, 1), salida.Mensaje);
        }