-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from gamousquesORT/codigoAgosto23
Codigo agosto23
- Loading branch information
Showing
22 changed files
with
530 additions
and
12 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
CleanCode/Ejemplos/ConditionalTofunct/ConditionalTofunct.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace ConditionalTofunct; | ||
|
||
public class PlaceHolder | ||
{ | ||
public DateTime FechaExpiracion { get; set; } | ||
public bool AprobadoParaConsumo { get; set; } | ||
public int IdInspector { get; set; } | ||
|
||
public bool IsComestible() | ||
{ | ||
if (FechaExpiracion > DateTime.Now && AprobadoParaConsumo | ||
&& AprobadoParaConsumo == true && IdInspector !=0) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
Console.WriteLine("Hello, World!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...nCode/Ejemplos/WithoutDemeter/Commerce.cs → CleanCode/Ejemplos/WithoutDemeter/Store.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
TDD/RefactoringExamples/RefactoringExamples/OriginalCode/OriginalCode.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
34 changes: 34 additions & 0 deletions
34
TDD/RefactoringExamples/RefactoringExamples/OriginalCode/operations_on_numbers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace OriginalCode; | ||
|
||
public class operations_on_numbers | ||
{ | ||
private int total; | ||
private int contador; | ||
|
||
public operations_on_numbers() | ||
{ | ||
total = 0; | ||
contador = 0; | ||
} | ||
|
||
public int magic_function(List<int> ns) | ||
{ | ||
foreach (int n in ns) | ||
{ | ||
if (n % 2 == 0) | ||
{ | ||
total += n; | ||
contador++; | ||
} | ||
} | ||
|
||
if (contador == 0) | ||
{ | ||
throw new Exception("La lista no contiene numeros pares "); | ||
} | ||
else | ||
{ | ||
return total / contador; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
TDD/RefactoringExamples/RefactoringExamples/RefactoringExamples.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToRefactorExamples", "ToRefactorExamples\ToRefactorExamples.csproj", "{FE7BCF27-1F9C-4A46-AF71-944539A34BF1}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RefactoringExamplesTests", "RefactoringExamplesTests\RefactoringExamplesTests.csproj", "{4A1F1396-469A-44CF-A84F-5AF1164ABAF9}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OriginalCode", "OriginalCode\OriginalCode.csproj", "{C214ABEA-E7C3-435D-A89D-1C74A1D34029}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FE7BCF27-1F9C-4A46-AF71-944539A34BF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FE7BCF27-1F9C-4A46-AF71-944539A34BF1}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FE7BCF27-1F9C-4A46-AF71-944539A34BF1}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FE7BCF27-1F9C-4A46-AF71-944539A34BF1}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{4A1F1396-469A-44CF-A84F-5AF1164ABAF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{4A1F1396-469A-44CF-A84F-5AF1164ABAF9}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{4A1F1396-469A-44CF-A84F-5AF1164ABAF9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{4A1F1396-469A-44CF-A84F-5AF1164ABAF9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{C214ABEA-E7C3-435D-A89D-1C74A1D34029}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C214ABEA-E7C3-435D-A89D-1C74A1D34029}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C214ABEA-E7C3-435D-A89D-1C74A1D34029}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C214ABEA-E7C3-435D-A89D-1C74A1D34029}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
29 changes: 29 additions & 0 deletions
29
...ringExamples/RefactoringExamples/RefactoringExamplesTests/RefactoringExamplesTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2"/> | ||
<PackageReference Include="xunit" Version="2.4.2"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ToRefactorExamples\ToRefactorExamples.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
88 changes: 88 additions & 0 deletions
88
TDD/RefactoringExamples/RefactoringExamples/RefactoringExamplesTests/RefactoringTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using ToRefactorExamples; | ||
|
||
namespace RefactoringExamplesTests; | ||
|
||
public class RefactoringTests | ||
{ | ||
[Fact] | ||
public void Should_Return_the_Average_Given_a_Set_Of_One_Even_Number() | ||
{ | ||
List<int> numbers = new() {8}; | ||
operations_on_numbers rf = new operations_on_numbers(); | ||
int want = 8; | ||
int got = rf.magic_function(numbers); | ||
Assert.Equal(want, got); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_The_Average_Given_a_Set_Of_Two_Even_Numbers() | ||
{ | ||
List<int> numbers = new() { 2, 6 }; | ||
operations_on_numbers rf = new operations_on_numbers(); | ||
int want = 4; | ||
int got = rf.magic_function(numbers); | ||
Assert.Equal(want, got); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_The_Even_Number_Given_A_SetWith_One_Even_And_One_Odd_Number() | ||
{ | ||
List<int> numbers = new() { 2, 7 }; | ||
operations_on_numbers rf = new operations_on_numbers(); | ||
int want = 2; | ||
int got = rf.magic_function(numbers); | ||
Assert.Equal(want, got); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_The_Even_Number_Given_A_SetWith_More_Than_One_Even_And_One_Odd_Number() | ||
{ | ||
List<int> numbers = new() {0, 2, 7 }; | ||
operations_on_numbers rf = new operations_on_numbers(); | ||
int want = 1; | ||
int got = rf.magic_function(numbers); | ||
Assert.Equal(want, got); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_TheAverage_Given_An_Odd_SetOf_Even_Numbers_Including_Zero() | ||
{ | ||
List<int> numbers = new() {0, 2, 6, 8, 12, 24, 28 }; | ||
operations_on_numbers rf = new operations_on_numbers(); | ||
int want = Convert.ToInt32(numbers.Average()); | ||
int got = rf.magic_function(numbers); | ||
Assert.Equal(want, got); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_TheAverage_Given_ASetOf_Even_Numbers_Containing_a_Cero() | ||
{ | ||
List<int> numbers = new() {0, 6, 8, 12, 24, 28 }; | ||
operations_on_numbers rf = new operations_on_numbers(); | ||
int want = Convert.ToInt32(numbers.Average()); | ||
int got = rf.magic_function(numbers); | ||
Assert.Equal(want, got); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_ArgumentExcep_Given_An_Empty_Set() | ||
{ | ||
List<int> numbers = new(); | ||
operations_on_numbers rf = new operations_on_numbers(); | ||
|
||
// Renombre para usar la ArgumentException | ||
Assert.Throws<Exception>(() => rf.magic_function(numbers)); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_Message_Given_ASet_of_Odd_Numbers() | ||
{ | ||
List<int> numbers = new() { 1, 5, 7,35 }; | ||
operations_on_numbers rf = new operations_on_numbers(); | ||
string want = "La lista no contiene numeros pares"; | ||
var got = Assert.Throws<Exception>(() => rf.magic_function(numbers)); | ||
Assert.Contains(want, got.Message); | ||
} | ||
|
||
|
||
} |
1 change: 1 addition & 0 deletions
1
TDD/RefactoringExamples/RefactoringExamples/RefactoringExamplesTests/Usings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
9 changes: 9 additions & 0 deletions
9
TDD/RefactoringExamples/RefactoringExamples/ToRefactorExamples/ToRefactorExamples.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
44 changes: 44 additions & 0 deletions
44
TDD/RefactoringExamples/RefactoringExamples/ToRefactorExamples/operations_on_numbers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace ToRefactorExamples; | ||
|
||
/* - Cambiar todos los Nombres no significativos a significativos. | ||
* - Utilizar la convención de C# de programación y en Ingles | ||
* - Refactoree y aplique Clean Code en todo el código | ||
* ->reemplazar números magicos | ||
* ->reemplazar comentarios por nombres significativos | ||
* -> extraer métodos | ||
* | ||
*/ | ||
public class operations_on_numbers | ||
{ | ||
private int total; | ||
private int contador; | ||
|
||
public operations_on_numbers() | ||
{ | ||
total = 0; | ||
contador = 0; | ||
} | ||
|
||
public int magic_function(List<int> ns) | ||
{ | ||
foreach (int n in ns) | ||
{ | ||
if (n % 2 == 0) | ||
{ | ||
total += n; | ||
contador++; | ||
} | ||
} | ||
|
||
if (contador == 0) | ||
{ | ||
throw new Exception("La lista no contiene numeros pares "); | ||
} | ||
else | ||
{ | ||
return total / contador; | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FizzBuzzProdCode", "FizzBuzzProdCode\FizzBuzzProdCode.csproj", "{429E1E85-D105-4130-A929-8CFE50A1323C}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FizzBuzzTest", "FizzBuzzTest\FizzBuzzTest.csproj", "{1FAFDCE2-618A-4038-93DA-22C6C81764F9}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{429E1E85-D105-4130-A929-8CFE50A1323C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{429E1E85-D105-4130-A929-8CFE50A1323C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{429E1E85-D105-4130-A929-8CFE50A1323C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{429E1E85-D105-4130-A929-8CFE50A1323C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{1FAFDCE2-618A-4038-93DA-22C6C81764F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1FAFDCE2-618A-4038-93DA-22C6C81764F9}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1FAFDCE2-618A-4038-93DA-22C6C81764F9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1FAFDCE2-618A-4038-93DA-22C6C81764F9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.