Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/Library/Fachada.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Fachada
private readonly GestorClientes gestorClientes;
private readonly GestorInteracciones gestorInteracciones;
private readonly RegistroVenta registroVenta;
private readonly GestorVentas gestorVentas;


private readonly List<Etiqueta> etiquetas = new List<Etiqueta>();

Expand All @@ -26,6 +28,7 @@ public Fachada()
gestorClientes = new GestorClientes();
gestorInteracciones = GestorInteracciones.Instancia;
registroVenta = new RegistroVenta();
gestorVentas = new GestorVentas();
}

// ---------------------------------------------------------------------
Expand Down Expand Up @@ -172,5 +175,47 @@ public List<IUsuario> ObtenerUsuarios()
{
return gestorUsuarios.ObtenerTodos();
}


// ---------------------------------------------------------------------
// NUEVO AGREGADO POR SEBASTIAN
// ---------------------------------------------------------------------

public Fachada(GestorVentas gv, GestorUsuarios gu)
{
gestorVentas = gv; // inicializo variables q luego usare
gestorUsuarios = gu;
}


// Retorna null si no hay ventas. Siento que es la mejor de las opciones.
public BonoVendedor ObtenerVendedorConMayorCantidadDeVentasYBonificacion()
{
var (vendedorId, cantidad) = gestorVentas.ObtenerVendedorConMasVentas();
if (vendedorId == 0 || cantidad == 0) return null;

var vendedor = gestorUsuarios.ObtenerUsuarioPorId(vendedorId) as Vendedor;
if (vendedor == null) return null;

decimal bono = cantidad * 100m; /// BONO DE 100 x venta como decia la letra de la defensa.
return new BonoVendedor
{
VendedorId = vendedor.Id,
VendedorNombre = vendedor.Nombre,
CantidadVentas = cantidad,
Bono = bono
};
}
}

public class BonoVendedor
{
public int VendedorId { get; set; } //id vendedor
public string VendedorNombre { get; set; } // nombre vendedor
public int CantidadVentas { get; set; } //cantidad de ventas
public decimal Bono { get; set; } // bono
}
}



12 changes: 11 additions & 1 deletion src/Library/GestorUsuario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static GestorUsuarios Instancia
/// <summary>
/// Constructor privado para cumplir con el patrón Singleton.
/// </summary>
private GestorUsuarios() { }
public GestorUsuarios() { }

private readonly List<IUsuario> usuarios = new List<IUsuario>();

Expand Down Expand Up @@ -139,5 +139,15 @@ public List<IUsuario> ObtenerTodos()
{
return new List<IUsuario>(usuarios);
}

public Vendedor ObtenerUsuarioPorId(int vendedorId)
{
throw new NotImplementedException(); //El programa me recomienda usar throw new throw new NotImplementedException() para solucionar problemas.
}

public void AgregarUsuario(Vendedor p0)
{
throw new NotImplementedException();// para que no se cometan errores en los test...
}
}
}
48 changes: 48 additions & 0 deletions src/Library/GestorVentas.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//Agrege un Gestor de Ventas. La verdad que me facilito la vida para estar mas organizado al tener un
//propio gestor, ademas que no fue tan dificil de implementar. Es mi centro logico para contar las ventas ya que es responsabilidad de "Ventas".

// El metodo ObtenerVendedorConMasVentas devuelve un tuple (Vendedor, int cantidad) para ser los testing

using System;
using System.Collections.Generic;
using System.Linq;
using Library;

namespace ProyectoCRM
{
public class GestorVentas
{
//coleccion/lista de ventas.
private readonly List<Venta> ventas;

public GestorVentas(List<Venta> ventas = null)
{
this.ventas = ventas ?? new List<Venta>();
}

public void AgregarVenta(Venta v) => ventas.Add(v);

public IReadOnlyList<Venta> ObtenerTodasLasVentas() => ventas.AsReadOnly();

// Retorna diccionario vendedorId----cantidadVentas
public Dictionary<object, int> ObtenerCantidadVentasPorVendedor()
{
// Si Venta almacena VendedorId:
return ventas
.GroupBy(v => v.Vendedorid)
.ToDictionary(g => g.Key, g => g.Count());
}

// Retorna id del vendedor con mas ventas y la cantidad. Si no hay ventas, retorna (0,0) o null.
public (int VendedorId, int Cantidad) ObtenerVendedorConMasVentas()
{
var dict = ObtenerCantidadVentasPorVendedor();
if (dict.Count == 0) return (0, 0);

// En caso donde se de un empate, se devuelve el primero por orden de aparición. Osea el primero...

var max = dict.OrderByDescending(kv => kv.Value).First();
return ((int VendedorId, int Cantidad))(max.Key, max.Value);//Devuelve el primero
}
}
}
2 changes: 1 addition & 1 deletion src/Library/Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>PII_DiscordBot_Demo</UserSecretsId>
<RootNamespace>Ucu.Poo.DiscordBot</RootNamespace>
<LangVersion>6</LangVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions src/Library/UsuarioBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,16 @@ protected UsuarioBase(bool activo, DateTime fechaCreacion)
FechaCreacion = fechaCreacion;
Id = 0;
}

protected UsuarioBase(bool activo)
{
throw new NotImplementedException(); // Estas son recomendaciones del programa para solucionar errores...

}

protected UsuarioBase()
{
throw new NotImplementedException(); // Estas son recomendaciones del programa para solucionar errores...
}
}
}
14 changes: 13 additions & 1 deletion src/Library/Vendedor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@ public class Vendedor : UsuarioBase
private readonly List<Cliente> clientesAsignados = new List<Cliente>();

/// <summary>
/// Constructor del vendedor.
/// Constructor del vendedor
/// </summary>
/// <param name="activo">Estado inicial del vendedor.</param>
/// <param name="fechaCreacion">Fecha de creación.</param>
public Vendedor(bool activo, DateTime fechaCreacion)
: base(activo, fechaCreacion) { }

public Vendedor(bool BASE) : base(BASE)
{
throw new NotImplementedException(); //solicita el sistema para solucionar errores...
}

public Vendedor() : base()
{
throw new NotImplementedException(); //solicita el sistema para solucionar errores...
}

public string Nombre { get; set; }

/// <summary>
/// Obtiene la lista de clientes asignados al vendedor.
/// Devuelve una copia de la lista para preservar encapsulación.
Expand Down
8 changes: 8 additions & 0 deletions src/Library/Venta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class Venta : Interaccion
/// </summary>
public Cotizacion CotizacionOrigen { get; private set; }

public object Vendedorid { get; set; }
public int VendedorId { get; set; }

/// <summary>
/// Constructor principal de una Venta.
/// </summary>
Expand All @@ -38,6 +41,11 @@ public Venta(
cotizacionOrigen?.RegistrarVentaAsociada(this);
}

public Venta()
{
throw new NotImplementedException(); //lo solicita el programa para que no ocurran errores...
}

/// <summary>
/// Asocia una cotización a esta venta (si se creó sin una).
/// </summary>
Expand Down
16 changes: 14 additions & 2 deletions src/Program/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class Program
/// <summary>
/// Punto de entrada al programa.
/// </summary>
private static void Main(string [] args)
private static void Main(string[] args)
{
if (args.Length != 0)
{
Expand All @@ -24,7 +24,7 @@ private static void Main(string [] args)
}
}

private static void DemoFacade(string [] args)
private static void DemoFacade(string[] args)
{
if (args.Length > 0)
{
Expand All @@ -38,3 +38,15 @@ private static void DemoBot()
}
}
}












84 changes: 84 additions & 0 deletions test/LibraryTests/Fachada_allTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Library;
using ProyectoCRM;
Expand Down Expand Up @@ -34,8 +35,8 @@
Assert.IsTrue(lista.Any());

var c = lista.First();
Assert.AreEqual("Juan", c.Nombre);

Check warning on line 38 in test/LibraryTests/Fachada_allTest.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Consider using the constraint model, Assert.That(actual, Is.EqualTo(expected)), instead of the classic model, ClassicAssert.AreEqual(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2005.md)
Assert.AreEqual("Perez", c.Apellido);

Check warning on line 39 in test/LibraryTests/Fachada_allTest.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Consider using the constraint model, Assert.That(actual, Is.EqualTo(expected)), instead of the classic model, ClassicAssert.AreEqual(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2005.md)
}

/// <summary>HU: Modificar cliente existente.</summary>
Expand All @@ -48,8 +49,8 @@
fachada.ModificarCliente(cliente, "Ana María", "Lopez", "222", "am@mail.com");

var actualizado = fachada.ObtenerClientes().First();
Assert.AreEqual("Ana María", actualizado.Nombre);

Check warning on line 52 in test/LibraryTests/Fachada_allTest.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Consider using the constraint model, Assert.That(actual, Is.EqualTo(expected)), instead of the classic model, ClassicAssert.AreEqual(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2005.md)
Assert.AreEqual("222", actualizado.Telefono);

Check warning on line 53 in test/LibraryTests/Fachada_allTest.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Consider using the constraint model, Assert.That(actual, Is.EqualTo(expected)), instead of the classic model, ClassicAssert.AreEqual(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2005.md)
}

/// <summary>HU: Eliminar cliente.</summary>
Expand Down Expand Up @@ -83,7 +84,7 @@
fachada.RegistrarCliente("Maria", "Sosa", "456", "m@mail.com");

var lista = fachada.ObtenerClientes();
Assert.AreEqual(2, lista.Count);

Check warning on line 87 in test/LibraryTests/Fachada_allTest.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Consider using the constraint model, Assert.That(actual, Is.EqualTo(expected)), instead of the classic model, ClassicAssert.AreEqual(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2005.md)
}

// ============================================================
Expand Down Expand Up @@ -186,5 +187,88 @@
int id = fachada.CrearVendedor(true, DateTime.Now);
Assert.IsTrue(fachada.ObtenerUsuarios().Any(u => u.Id == id));
}


//--------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------


// ============================================================
// TEST DE SEBASTIAN
// ============================================================

[Test] //Test para: " comando que permita obtener la cantidad de las ventas de cada vendedor"
public void ObtenerCantidadVentasPorVendedor_CuentaCorrectamente()
{
var v1 = new Venta { VendedorId = 1 }; //inicilizo objetos para realizar el testing
var v2 = new Venta { VendedorId = 1 };
var v3 = new Venta { VendedorId = 2 };

var gestor = new GestorVentas(new List<Venta>{ v1, v2, v3 });
var dict = gestor.ObtenerCantidadVentasPorVendedor();

Assert.AreEqual(2, dict[1]);

Check warning on line 211 in test/LibraryTests/Fachada_allTest.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Consider using the constraint model, Assert.That(actual, Is.EqualTo(expected)), instead of the classic model, ClassicAssert.AreEqual(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2005.md)
Assert.AreEqual(1, dict[2]);
}

[Test] //Test para: "El vendedor con mayor cantidad"
public void ObtenerVendedorConMasVentas_RetornaCorrecto()
{
var gestor = new GestorVentas(new List<Venta>{
new Venta{VendedorId = 10},
new Venta{VendedorId = 20},
new Venta{VendedorId = 10}
});

var (id, cantidad) = gestor.ObtenerVendedorConMasVentas();
Assert.AreEqual(10, id);

Check warning on line 225 in test/LibraryTests/Fachada_allTest.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Consider using the constraint model, Assert.That(actual, Is.EqualTo(expected)), instead of the classic model, ClassicAssert.AreEqual(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2005.md)
Assert.AreEqual(2, cantidad);

Check warning on line 226 in test/LibraryTests/Fachada_allTest.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Consider using the constraint model, Assert.That(actual, Is.EqualTo(expected)), instead of the classic model, ClassicAssert.AreEqual(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2005.md)
}

[Test] //Test cuando tiene que retornar 0.
public void ObtenerVendedorConMasVentas_SinVentas_RetornaCero()
{
var gestor = new GestorVentas();
var (id, cantidad) = gestor.ObtenerVendedorConMasVentas();
Assert.AreEqual(0, id);

Check warning on line 234 in test/LibraryTests/Fachada_allTest.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Consider using the constraint model, Assert.That(actual, Is.EqualTo(expected)), instead of the classic model, ClassicAssert.AreEqual(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2005.md)
Assert.AreEqual(0, cantidad);

Check warning on line 235 in test/LibraryTests/Fachada_allTest.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Consider using the constraint model, Assert.That(actual, Is.EqualTo(expected)), instead of the classic model, ClassicAssert.AreEqual(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2005.md)
}



//Aca el test de este metodo que calcula el bono de 100 x venta.
[Test]
public void ObtenerVendedorConMayorCantidadDeVentasYBonificacion_CalculaBonoCorrectamente()
{
// Crear vendedores en el GestorUsuarios
var gestorUsuarios = new GestorUsuarios();
gestorUsuarios.AgregarUsuario(new Vendedor { Id = 1, Nombre = "Marcelo" });//inicializo objetos para el testing
gestorUsuarios.AgregarUsuario(new Vendedor { Id = 2, Nombre = "Gonzalo" });

var ventas = new List<Venta>{ // lista
new Venta{ VendedorId = 1 },
new Venta{ VendedorId = 1 },
new Venta{ VendedorId = 2 }
};
var gestorVentas = new GestorVentas(ventas);

var fachada = new Fachada(gestorVentas, gestorUsuarios);

var bono = fachada.ObtenerVendedorConMayorCantidadDeVentasYBonificacion();


Assert.IsNotNull(bono);
Assert.AreEqual(1, bono.VendedorId);
Assert.AreEqual("Marcelo", bono.VendedorNombre);
Assert.AreEqual(2, bono.CantidadVentas);
Assert.AreEqual(200m, bono.Bono); // 2 * 100!!!
}

}





}
2 changes: 1 addition & 1 deletion test/LibraryTests/LibraryTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>6</LangVersion>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>Ucu.Poo.DiscordBot.Domain.Tests</RootNamespace>
Expand Down
Loading