├── Code ├── DependencyInjectionWithGuice.Java │ ├── .classpath │ ├── .gitignore │ ├── README.md │ ├── lib │ │ ├── aopalliance-1.0.jar │ │ ├── failureaccess-1.0.3.jar │ │ ├── guava-33.4.8-jre.jar │ │ ├── guice-6.0.0.jar │ │ ├── jakarta.inject-api-2.0.1.jar │ │ └── javax.inject-1.jar │ └── src │ │ └── diwithguice │ │ ├── ConfiguratorModule.java │ │ ├── IServiceConsumer.java │ │ ├── IWriter.java │ │ ├── MainClass.java │ │ ├── MyWriter.java │ │ ├── ServiceConsumerWithCtor.java │ │ └── ServiceConsumerWithSetter.java ├── Lib │ ├── aopalliance-1.0.jar │ ├── failureaccess-1.0.3.jar │ ├── guava-33.4.8-jre.jar │ ├── guice-6.0.0.jar │ ├── jakarta.inject-api-2.0.1.jar │ ├── javax.inject-1.jar │ ├── javax.servlet-api-4.0.1.jar │ └── json-20250107.jar ├── OfRectanglesAndSquares.Java │ ├── .classpath │ ├── .gitignore │ ├── .project │ ├── README.md │ └── src │ │ └── OfRectanglesAndSquares │ │ ├── App.java │ │ ├── Calculator.java │ │ ├── CalculatorWithOptimization.java │ │ ├── ICalculator.java │ │ ├── IRectangle.java │ │ ├── Rectangle.java │ │ ├── RectangleWithRound.java │ │ ├── SingletonClass.java │ │ └── Square.java ├── OfRectanglesAndSquares │ ├── .gitignore │ ├── OfRectanglesAndSquares.sln │ └── OfRectanglesAndSquares │ │ ├── Calculator.cs │ │ ├── CalculatorWithOptimization.cs │ │ ├── ICalculator.cs │ │ ├── IRectangle.cs │ │ ├── OfRectanglesAndSquares.csproj │ │ ├── Program.cs │ │ ├── Rectangle.cs │ │ ├── RectangleWithRound.cs │ │ └── Square.cs ├── WebSvc.Java │ ├── .classpath │ ├── .gitignore │ ├── .project │ ├── .settings │ │ ├── .jsdtscope │ │ ├── org.eclipse.jdt.core.prefs │ │ ├── org.eclipse.wst.common.component │ │ ├── org.eclipse.wst.common.project.facet.core.xml │ │ ├── org.eclipse.wst.jsdt.ui.superType.container │ │ └── org.eclipse.wst.jsdt.ui.superType.name │ ├── lib │ │ ├── javax.servlet-api-4.0.1.jar │ │ └── json-20250107.jar │ └── src │ │ └── main │ │ ├── java │ │ ├── models │ │ │ └── Person.java │ │ ├── repositories │ │ │ ├── IDb.java │ │ │ ├── InMemoryDb.java │ │ │ └── MongoDB.java │ │ ├── services │ │ │ ├── IEnvironment.java │ │ │ ├── IPersonaService.java │ │ │ ├── ISvcBuilder.java │ │ │ ├── PersonaService.java │ │ │ ├── ServiceBuilder.java │ │ │ └── TheEnvironment.java │ │ ├── unitTests │ │ │ ├── MockThatThrowsException.java │ │ │ ├── MyHttpServletRequest.java │ │ │ ├── MyHttpServletResponse.java │ │ │ ├── MyServletTest.java │ │ │ └── ServicesBuilderForMocks.java │ │ ├── utils │ │ │ ├── Mapper.java │ │ │ └── WebUtils.java │ │ └── web │ │ │ ├── MyServlet.java │ │ │ └── MyServletNoClean.java │ │ └── webapp │ │ └── META-INF │ │ └── MANIFEST.MF ├── WebSvc.dotNet │ ├── .gitignore │ ├── Tests │ │ ├── Factories │ │ │ └── TestApplicationFactory.cs │ │ ├── MSTestSettings.cs │ │ ├── Mocks │ │ │ └── DbMockThatThrowsException.cs │ │ ├── MySvcTests.cs │ │ └── Tests.csproj │ ├── WebSvc.dotNet.sln │ └── WebSvc.dotNet │ │ ├── Controllers │ │ └── MySvcController.cs │ │ ├── Dto │ │ └── MySvcPostPayload.cs │ │ ├── Helpers │ │ ├── AutoMapperProfile.cs │ │ └── MyAgeValidator.cs │ │ ├── Model │ │ └── Person.cs │ │ ├── Program.cs │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── Repositories │ │ ├── IDb.cs │ │ ├── InMemoryDb.cs │ │ └── MongoDb.cs │ │ ├── WebSvc.dotNet.csproj │ │ ├── WebSvc.dotNet.http │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ └── appsettings.local.json ├── WebSvc │ ├── .gitignore │ ├── WebSvc.sln │ └── WebSvc │ │ ├── Controllers │ │ └── MySvcController.cs │ │ ├── Program.cs │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── Repositories │ │ ├── IDb.cs │ │ ├── InMemoryDb.cs │ │ └── MongoDB.cs │ │ ├── Services │ │ ├── IEnvironment.cs │ │ ├── ISvcBuilder.cs │ │ ├── ServiceBuilder.cs │ │ └── TheEnvironment.cs │ │ ├── UnitTests │ │ ├── MockThatThrowsException.cs │ │ ├── MyControllerTest.cs │ │ └── ServicesBuilderForMocks.cs │ │ ├── WebSvc.csproj │ │ ├── WebSvc.http │ │ ├── appsettings.Development.json │ │ └── appsettings.json └── dotNetBasics │ ├── .gitignore │ ├── ConsoleApp │ ├── ConsoleApp.csproj │ ├── IMyList.cs │ ├── MyDataType.cs │ ├── MyList.cs │ ├── MyModel.cs │ ├── Program.cs │ └── README.md │ ├── MyClassLibrary │ ├── MyClass.cs │ ├── MyClassLibrary.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ └── README.md │ ├── MySharedProject │ ├── MyClass.cs │ ├── MySharedProject.projitems │ ├── MySharedProject.shproj │ └── README.md │ ├── UnitTests │ ├── MyClassLibraryUnitTest.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── README.md │ ├── UnitTests.csproj │ └── packages.config │ └── dotNetBasics.sln ├── Exams ├── 20240607 Scritto - Soluzione.pdf ├── 20240607 Scritto.pdf ├── 20240708 Scritto - Soluzione.pdf └── 20240708 Scritto.pdf ├── FAQ.md ├── LICENSE ├── README.md ├── Seminars └── La tutela del software aspetti tecnici e legali.pdf └── Slides ├── 00 - Course Introduction.pdf ├── 01 - Collaborative tools.pdf ├── 02 - The software design process.pdf ├── 03 - Requirements.pdf ├── 04 - Documentation - Notation and tools.pdf ├── 05 - Unified Modeling Language.pdf ├── 06 - System design.pdf ├── 07 - UML and OOP.pdf ├── 08 - Solid.pdf ├── 09 - Design patterns.pdf ├── 10 - CLEAN code architecture.pdf ├── 11 - dotNet and CSharp.pdf └── Precariato universitario.pdf /Code/DependencyInjectionWithGuice.Java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | .settings/ 3 | bin/ 4 | .project -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/README.md: -------------------------------------------------------------------------------- 1 | # Depencency Injection with Guice 2 | 3 | This is an example of usage of Google Guice for Dependency Injection in Java. 4 | 5 | ## To compile (Win Powershell) 6 | 7 | ``` 8 | > javac.exe -d ".\bin\" -cp ".\lib\guice-6.0.0.jar" .\src\diwithguice\ConfiguratorModule.java .\src\diwithguice\IServiceConsumer.java .\src\diwithguice\IWriter.java .\src\diwithguice\MainClass.java .\src\diwithguice\MyWriter.java .\src\diwithguice\ServiceConsumerWithSetter.java .\src\diwithguice\ServiceConsumerWithCtor.java 9 | ``` 10 | 11 | ## To run (Win Powershell) 12 | 13 | ``` 14 | > java.exe -cp ".\lib\aopalliance-1.0.jar;.\lib\failureaccess-1.0.3.jar;.\lib\guava-33.4.8-jre.jar;.\lib\guice-6.0.0.jar;.\lib\jakarta.inject-api-2.0.1.jar;.\lib\javax.inject-1.jar;.\src\" diwithguice.MainClass 15 | ``` -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/lib/aopalliance-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/DependencyInjectionWithGuice.Java/lib/aopalliance-1.0.jar -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/lib/failureaccess-1.0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/DependencyInjectionWithGuice.Java/lib/failureaccess-1.0.3.jar -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/lib/guava-33.4.8-jre.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/DependencyInjectionWithGuice.Java/lib/guava-33.4.8-jre.jar -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/lib/guice-6.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/DependencyInjectionWithGuice.Java/lib/guice-6.0.0.jar -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/lib/jakarta.inject-api-2.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/DependencyInjectionWithGuice.Java/lib/jakarta.inject-api-2.0.1.jar -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/lib/javax.inject-1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/DependencyInjectionWithGuice.Java/lib/javax.inject-1.jar -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/src/diwithguice/ConfiguratorModule.java: -------------------------------------------------------------------------------- 1 | package diwithguice; 2 | 3 | import com.google.inject.AbstractModule; 4 | 5 | public class ConfiguratorModule extends AbstractModule { 6 | 7 | @Override 8 | protected void configure() { 9 | bind(IWriter.class).to(MyWriter.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/src/diwithguice/IServiceConsumer.java: -------------------------------------------------------------------------------- 1 | package diwithguice; 2 | 3 | public interface IServiceConsumer { 4 | void run(); 5 | } 6 | -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/src/diwithguice/IWriter.java: -------------------------------------------------------------------------------- 1 | package diwithguice; 2 | 3 | /** 4 | * This is the interface to the service we want to inject 5 | */ 6 | public interface IWriter { 7 | 8 | void writer(String s); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/src/diwithguice/MainClass.java: -------------------------------------------------------------------------------- 1 | package diwithguice; 2 | 3 | import com.google.inject.Guice; 4 | import com.google.inject.Injector; 5 | 6 | public class MainClass { 7 | 8 | public static void main(String[] args) { 9 | Injector injector = Guice.createInjector(new ConfiguratorModule()); 10 | 11 | IServiceConsumer svcConsumer = injector.getInstance(ServiceConsumerWithSetter.class); 12 | //IServiceConsumer svcConsumer = injector.getInstance(ServiceConsumerWithCtor.class); 13 | 14 | svcConsumer.run(); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/src/diwithguice/MyWriter.java: -------------------------------------------------------------------------------- 1 | package diwithguice; 2 | 3 | /** 4 | * This is the interface to the service we want to inject 5 | */ 6 | public class MyWriter implements IWriter { 7 | 8 | @Override 9 | public void writer(String s) { 10 | System.out.println("The string is " + s); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/src/diwithguice/ServiceConsumerWithCtor.java: -------------------------------------------------------------------------------- 1 | package diwithguice; 2 | 3 | import com.google.inject.Inject; 4 | 5 | public class ServiceConsumerWithCtor implements IServiceConsumer { 6 | 7 | private IWriter _writer = null; 8 | 9 | @Inject 10 | public ServiceConsumerWithCtor(IWriter service) { 11 | this._writer = service; 12 | } 13 | 14 | public void run() { 15 | String s = "This is my test"; 16 | this._writer.writer(s); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Code/DependencyInjectionWithGuice.Java/src/diwithguice/ServiceConsumerWithSetter.java: -------------------------------------------------------------------------------- 1 | package diwithguice; 2 | 3 | import com.google.inject.Inject; 4 | 5 | public class ServiceConsumerWithSetter implements IServiceConsumer { 6 | private IWriter _writer = null; 7 | 8 | @Inject 9 | public void setWriter(IWriter service) { 10 | this._writer = service; 11 | } 12 | 13 | public void run() { 14 | String s = "This is my test"; 15 | this._writer.writer(s); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Code/Lib/aopalliance-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/Lib/aopalliance-1.0.jar -------------------------------------------------------------------------------- /Code/Lib/failureaccess-1.0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/Lib/failureaccess-1.0.3.jar -------------------------------------------------------------------------------- /Code/Lib/guava-33.4.8-jre.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/Lib/guava-33.4.8-jre.jar -------------------------------------------------------------------------------- /Code/Lib/guice-6.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/Lib/guice-6.0.0.jar -------------------------------------------------------------------------------- /Code/Lib/jakarta.inject-api-2.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/Lib/jakarta.inject-api-2.0.1.jar -------------------------------------------------------------------------------- /Code/Lib/javax.inject-1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/Lib/javax.inject-1.jar -------------------------------------------------------------------------------- /Code/Lib/javax.servlet-api-4.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/Lib/javax.servlet-api-4.0.1.jar -------------------------------------------------------------------------------- /Code/Lib/json-20250107.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/Lib/json-20250107.jar -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | replay_pid* 25 | 26 | .vscode/ 27 | /bin/ 28 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | OfRectanglesAndSquares.Java 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/README.md: -------------------------------------------------------------------------------- 1 | ## Getting Started 2 | 3 | Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. 4 | 5 | ## Folder Structure 6 | 7 | The workspace contains two folders by default, where: 8 | 9 | - `src`: the folder to maintain sources 10 | - `lib`: the folder to maintain dependencies 11 | 12 | Meanwhile, the compiled output files will be generated in the `bin` folder by default. 13 | 14 | > If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. 15 | 16 | ## Dependency Management 17 | 18 | The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). 19 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/src/OfRectanglesAndSquares/App.java: -------------------------------------------------------------------------------- 1 | package OfRectanglesAndSquares; 2 | 3 | public class App { 4 | 5 | public static void TestDoubleArea(IRectangle rectangle, ICalculator calculator) throws Exception { 6 | double area1, area2; 7 | area1 = calculator.calcArea(rectangle); 8 | 9 | rectangle.setWidth(rectangle.getWidth() * 2); 10 | area2 = calculator.calcArea(rectangle); 11 | 12 | // Test ok 13 | if (area2 == area1 * 2) 14 | return; 15 | 16 | // If test fails, throw exception 17 | throw new Exception("Test failed! Expected " + area1 + ", got " + area2); 18 | } 19 | 20 | public static void main(String[] args) throws Exception { 21 | 22 | ICalculator c = new Calculator(); 23 | 24 | // Test Rectangle #1 25 | IRectangle r = new Rectangle(4, 5); 26 | TestDoubleArea(r, c); 27 | 28 | // Test Rectangle #2 29 | r = new RectangleWithRound(2, 8); 30 | TestDoubleArea(r, c); 31 | 32 | // Test Square #1 33 | r = new Square(4); 34 | TestDoubleArea(r, c); 35 | 36 | // Test Square #2 37 | r = new Square(2); 38 | TestDoubleArea(r, c); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/src/OfRectanglesAndSquares/Calculator.java: -------------------------------------------------------------------------------- 1 | package OfRectanglesAndSquares; 2 | 3 | /** 4 | * This class performs che computation of an area 5 | */ 6 | public class Calculator implements ICalculator { 7 | 8 | /** 9 | * Compute the area of a Rectangle 10 | */ 11 | public double calcArea(IRectangle r) { 12 | return r.getHeight() * r.getWidth(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/src/OfRectanglesAndSquares/CalculatorWithOptimization.java: -------------------------------------------------------------------------------- 1 | package OfRectanglesAndSquares; 2 | 3 | /** 4 | * This class has an optimized calculus algorithm 5 | */ 6 | public class CalculatorWithOptimization extends Calculator { 7 | 8 | public double CalcArea(IRectangle r) { 9 | if (r.getWidth() == 0.0) return 0.0; 10 | if (r.getHeight() == 0.0) return 0.0; 11 | 12 | return super.calcArea(r); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/src/OfRectanglesAndSquares/ICalculator.java: -------------------------------------------------------------------------------- 1 | package OfRectanglesAndSquares; 2 | 3 | public interface ICalculator { 4 | double calcArea(IRectangle r); 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/src/OfRectanglesAndSquares/IRectangle.java: -------------------------------------------------------------------------------- 1 | package OfRectanglesAndSquares; 2 | 3 | public interface IRectangle { 4 | 5 | /** 6 | * Sets the height of a Rectangle 7 | * @param height 8 | */ 9 | void setHeight(double height); 10 | 11 | /** 12 | * Sets the width of a Rectangle 13 | * @param height 14 | */ 15 | void setWidth(double width); 16 | 17 | /** 18 | * Gets the width of a Rectangle 19 | * @param height 20 | */ 21 | double getWidth(); 22 | 23 | /** 24 | * Gets the height of a Rectangle 25 | * @param height 26 | */ 27 | double getHeight(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/src/OfRectanglesAndSquares/Rectangle.java: -------------------------------------------------------------------------------- 1 | package OfRectanglesAndSquares; 2 | /** 3 | * This class handles the status of a Rectangle 4 | */ 5 | public class Rectangle implements IRectangle { 6 | private double _height; 7 | private double _width; 8 | 9 | public void setHeight(double height) { 10 | this._height = height; 11 | } 12 | 13 | public void setWidth(double width) { 14 | this._width = width; 15 | } 16 | 17 | public double getWidth() { 18 | return this._width; 19 | } 20 | 21 | public double getHeight() { 22 | return this._height; 23 | } 24 | 25 | public Rectangle(double height, double width) { 26 | this._height = height; 27 | this._width = width; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/src/OfRectanglesAndSquares/RectangleWithRound.java: -------------------------------------------------------------------------------- 1 | package OfRectanglesAndSquares; 2 | 3 | /** 4 | * This class rounds Rectangle height and width on sets to the ceiling integer 5 | */ 6 | public class RectangleWithRound extends Rectangle { 7 | 8 | public RectangleWithRound(double height, double width) { 9 | super(height, width); 10 | } 11 | 12 | public void setHeight(double height) { 13 | super.setHeight(Math.ceil(height)); 14 | } 15 | 16 | public void setWidth(double width) { 17 | super.setWidth(Math.ceil(width)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/src/OfRectanglesAndSquares/SingletonClass.java: -------------------------------------------------------------------------------- 1 | package OfRectanglesAndSquares; 2 | 3 | public class SingletonClass { 4 | static private SingletonClass _obj = null; 5 | 6 | private SingletonClass(){} 7 | 8 | public static SingletonClass getInstance() 9 | { 10 | if(_obj == null) 11 | _obj = new SingletonClass(); 12 | 13 | return _obj; 14 | } 15 | 16 | public void count() 17 | { 18 | this._counter ++; 19 | } 20 | private int _counter = 0; 21 | } 22 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares.Java/src/OfRectanglesAndSquares/Square.java: -------------------------------------------------------------------------------- 1 | package OfRectanglesAndSquares; 2 | 3 | /** 4 | * This class stores the status of a Square object 5 | */ 6 | public class Square extends Rectangle { 7 | 8 | public void setWidth(double width) { 9 | super.setWidth(width); 10 | super.setHeight(width); 11 | } 12 | 13 | public void setHeight(double height) { 14 | super.setHeight(height); 15 | super.setWidth(height); 16 | } 17 | 18 | public Square(double side) { 19 | super(side, side); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | # but not Directory.Build.rsp, as it configures directory-level build defaults 86 | !Directory.Build.rsp 87 | *.sbr 88 | *.tlb 89 | *.tli 90 | *.tlh 91 | *.tmp 92 | *.tmp_proj 93 | *_wpftmp.csproj 94 | *.log 95 | *.tlog 96 | *.vspscc 97 | *.vssscc 98 | .builds 99 | *.pidb 100 | *.svclog 101 | *.scc 102 | 103 | # Chutzpah Test files 104 | _Chutzpah* 105 | 106 | # Visual C++ cache files 107 | ipch/ 108 | *.aps 109 | *.ncb 110 | *.opendb 111 | *.opensdf 112 | *.sdf 113 | *.cachefile 114 | *.VC.db 115 | *.VC.VC.opendb 116 | 117 | # Visual Studio profiler 118 | *.psess 119 | *.vsp 120 | *.vspx 121 | *.sap 122 | 123 | # Visual Studio Trace Files 124 | *.e2e 125 | 126 | # TFS 2012 Local Workspace 127 | $tf/ 128 | 129 | # Guidance Automation Toolkit 130 | *.gpState 131 | 132 | # ReSharper is a .NET coding add-in 133 | _ReSharper*/ 134 | *.[Rr]e[Ss]harper 135 | *.DotSettings.user 136 | 137 | # TeamCity is a build add-in 138 | _TeamCity* 139 | 140 | # DotCover is a Code Coverage Tool 141 | *.dotCover 142 | 143 | # AxoCover is a Code Coverage Tool 144 | .axoCover/* 145 | !.axoCover/settings.json 146 | 147 | # Coverlet is a free, cross platform Code Coverage Tool 148 | coverage*.json 149 | coverage*.xml 150 | coverage*.info 151 | 152 | # Visual Studio code coverage results 153 | *.coverage 154 | *.coveragexml 155 | 156 | # NCrunch 157 | _NCrunch_* 158 | .*crunch*.local.xml 159 | nCrunchTemp_* 160 | 161 | # MightyMoose 162 | *.mm.* 163 | AutoTest.Net/ 164 | 165 | # Web workbench (sass) 166 | .sass-cache/ 167 | 168 | # Installshield output folder 169 | [Ee]xpress/ 170 | 171 | # DocProject is a documentation generator add-in 172 | DocProject/buildhelp/ 173 | DocProject/Help/*.HxT 174 | DocProject/Help/*.HxC 175 | DocProject/Help/*.hhc 176 | DocProject/Help/*.hhk 177 | DocProject/Help/*.hhp 178 | DocProject/Help/Html2 179 | DocProject/Help/html 180 | 181 | # Click-Once directory 182 | publish/ 183 | 184 | # Publish Web Output 185 | *.[Pp]ublish.xml 186 | *.azurePubxml 187 | # Note: Comment the next line if you want to checkin your web deploy settings, 188 | # but database connection strings (with potential passwords) will be unencrypted 189 | *.pubxml 190 | *.publishproj 191 | 192 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 193 | # checkin your Azure Web App publish settings, but sensitive information contained 194 | # in these scripts will be unencrypted 195 | PublishScripts/ 196 | 197 | # NuGet Packages 198 | *.nupkg 199 | # NuGet Symbol Packages 200 | *.snupkg 201 | # The packages folder can be ignored because of Package Restore 202 | **/[Pp]ackages/* 203 | # except build/, which is used as an MSBuild target. 204 | !**/[Pp]ackages/build/ 205 | # Uncomment if necessary however generally it will be regenerated when needed 206 | #!**/[Pp]ackages/repositories.config 207 | # NuGet v3's project.json files produces more ignorable files 208 | *.nuget.props 209 | *.nuget.targets 210 | 211 | # Microsoft Azure Build Output 212 | csx/ 213 | *.build.csdef 214 | 215 | # Microsoft Azure Emulator 216 | ecf/ 217 | rcf/ 218 | 219 | # Windows Store app package directories and files 220 | AppPackages/ 221 | BundleArtifacts/ 222 | Package.StoreAssociation.xml 223 | _pkginfo.txt 224 | *.appx 225 | *.appxbundle 226 | *.appxupload 227 | 228 | # Visual Studio cache files 229 | # files ending in .cache can be ignored 230 | *.[Cc]ache 231 | # but keep track of directories ending in .cache 232 | !?*.[Cc]ache/ 233 | 234 | # Others 235 | ClientBin/ 236 | ~$* 237 | *~ 238 | *.dbmdl 239 | *.dbproj.schemaview 240 | *.jfm 241 | *.pfx 242 | *.publishsettings 243 | orleans.codegen.cs 244 | 245 | # Including strong name files can present a security risk 246 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 247 | #*.snk 248 | 249 | # Since there are multiple workflows, uncomment next line to ignore bower_components 250 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 251 | #bower_components/ 252 | 253 | # RIA/Silverlight projects 254 | Generated_Code/ 255 | 256 | # Backup & report files from converting an old project file 257 | # to a newer Visual Studio version. Backup files are not needed, 258 | # because we have git ;-) 259 | _UpgradeReport_Files/ 260 | Backup*/ 261 | UpgradeLog*.XML 262 | UpgradeLog*.htm 263 | ServiceFabricBackup/ 264 | *.rptproj.bak 265 | 266 | # SQL Server files 267 | *.mdf 268 | *.ldf 269 | *.ndf 270 | 271 | # Business Intelligence projects 272 | *.rdl.data 273 | *.bim.layout 274 | *.bim_*.settings 275 | *.rptproj.rsuser 276 | *- [Bb]ackup.rdl 277 | *- [Bb]ackup ([0-9]).rdl 278 | *- [Bb]ackup ([0-9][0-9]).rdl 279 | 280 | # Microsoft Fakes 281 | FakesAssemblies/ 282 | 283 | # GhostDoc plugin setting file 284 | *.GhostDoc.xml 285 | 286 | # Node.js Tools for Visual Studio 287 | .ntvs_analysis.dat 288 | node_modules/ 289 | 290 | # Visual Studio 6 build log 291 | *.plg 292 | 293 | # Visual Studio 6 workspace options file 294 | *.opt 295 | 296 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 297 | *.vbw 298 | 299 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 300 | *.vbp 301 | 302 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 303 | *.dsw 304 | *.dsp 305 | 306 | # Visual Studio 6 technical files 307 | *.ncb 308 | *.aps 309 | 310 | # Visual Studio LightSwitch build output 311 | **/*.HTMLClient/GeneratedArtifacts 312 | **/*.DesktopClient/GeneratedArtifacts 313 | **/*.DesktopClient/ModelManifest.xml 314 | **/*.Server/GeneratedArtifacts 315 | **/*.Server/ModelManifest.xml 316 | _Pvt_Extensions 317 | 318 | # Paket dependency manager 319 | .paket/paket.exe 320 | paket-files/ 321 | 322 | # FAKE - F# Make 323 | .fake/ 324 | 325 | # CodeRush personal settings 326 | .cr/personal 327 | 328 | # Python Tools for Visual Studio (PTVS) 329 | __pycache__/ 330 | *.pyc 331 | 332 | # Cake - Uncomment if you are using it 333 | # tools/** 334 | # !tools/packages.config 335 | 336 | # Tabs Studio 337 | *.tss 338 | 339 | # Telerik's JustMock configuration file 340 | *.jmconfig 341 | 342 | # BizTalk build output 343 | *.btp.cs 344 | *.btm.cs 345 | *.odx.cs 346 | *.xsd.cs 347 | 348 | # OpenCover UI analysis results 349 | OpenCover/ 350 | 351 | # Azure Stream Analytics local run output 352 | ASALocalRun/ 353 | 354 | # MSBuild Binary and Structured Log 355 | *.binlog 356 | 357 | # NVidia Nsight GPU debugger configuration file 358 | *.nvuser 359 | 360 | # MFractors (Xamarin productivity tool) working folder 361 | .mfractor/ 362 | 363 | # Local History for Visual Studio 364 | .localhistory/ 365 | 366 | # Visual Studio History (VSHistory) files 367 | .vshistory/ 368 | 369 | # BeatPulse healthcheck temp database 370 | healthchecksdb 371 | 372 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 373 | MigrationBackup/ 374 | 375 | # Ionide (cross platform F# VS Code tools) working folder 376 | .ionide/ 377 | 378 | # Fody - auto-generated XML schema 379 | FodyWeavers.xsd 380 | 381 | # VS Code files for those working on multiple tools 382 | .vscode/* 383 | !.vscode/settings.json 384 | !.vscode/tasks.json 385 | !.vscode/launch.json 386 | !.vscode/extensions.json 387 | *.code-workspace 388 | 389 | # Local History for Visual Studio Code 390 | .history/ 391 | 392 | # Windows Installer files from build outputs 393 | *.cab 394 | *.msi 395 | *.msix 396 | *.msm 397 | *.msp 398 | 399 | # JetBrains Rider 400 | *.sln.iml 401 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares/OfRectanglesAndSquares.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.12.35728.132 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OfRectanglesAndSquares", "OfRectanglesAndSquares\OfRectanglesAndSquares.csproj", "{7A1A44C3-C602-4600-9CBE-4E1368226643}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7C9D156F-89A4-4B49-918F-0E079C84A5EA}" 9 | ProjectSection(SolutionItems) = preProject 10 | .gitignore = .gitignore 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {7A1A44C3-C602-4600-9CBE-4E1368226643}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {7A1A44C3-C602-4600-9CBE-4E1368226643}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {7A1A44C3-C602-4600-9CBE-4E1368226643}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {7A1A44C3-C602-4600-9CBE-4E1368226643}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares/OfRectanglesAndSquares/Calculator.cs: -------------------------------------------------------------------------------- 1 | namespace OfRectanglesAndSquares 2 | { 3 | /// 4 | /// This class performs che computation of an area 5 | /// TODO interface segregation 6 | /// 7 | public class Calculator : ICalculator 8 | { 9 | /// 10 | /// Compute the area of a Rectangle 11 | /// 12 | /// 13 | /// 14 | public virtual double CalcArea(IRectangle r) 15 | { 16 | return r.GetHeight() * r.GetWidth(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares/OfRectanglesAndSquares/CalculatorWithOptimization.cs: -------------------------------------------------------------------------------- 1 | namespace OfRectanglesAndSquares 2 | { 3 | /// 4 | /// This class has an optimized calculus algorithm 5 | /// 6 | public class CalculatorWithOptimization : Calculator 7 | { 8 | public override double CalcArea(IRectangle r) 9 | { 10 | if (r.GetWidth() == 0.0) return 0.0; 11 | if (r.GetHeight() == 0.0) return 0.0; 12 | 13 | return base.CalcArea(r); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares/OfRectanglesAndSquares/ICalculator.cs: -------------------------------------------------------------------------------- 1 | namespace OfRectanglesAndSquares 2 | { 3 | public interface ICalculator 4 | { 5 | double CalcArea(IRectangle r); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares/OfRectanglesAndSquares/IRectangle.cs: -------------------------------------------------------------------------------- 1 | namespace OfRectanglesAndSquares 2 | { 3 | public interface IRectangle 4 | { 5 | void SetHeight(double height); 6 | 7 | void SetWidth(double width); 8 | 9 | /// 10 | /// Returns the width of a Rectangle 11 | /// 12 | /// 13 | double GetWidth(); 14 | 15 | /// 16 | /// Returns the height of a Rectangle 17 | /// 18 | /// 19 | double GetHeight(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares/OfRectanglesAndSquares/OfRectanglesAndSquares.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares/OfRectanglesAndSquares/Program.cs: -------------------------------------------------------------------------------- 1 | using OfRectanglesAndSquares; 2 | 3 | /// 4 | /// This is our main test class. 5 | /// TODO is this really single responsibility? 6 | /// 7 | public class Program 8 | { 9 | /// 10 | /// Test for area doubled upon doubling the width 11 | /// TODO Interface segregation 12 | /// TODO rename function and introduce the concept of Asserts/TDD 13 | /// 14 | /// 15 | /// 16 | public static void TestDoubleArea(IRectangle rectangle, ICalculator calculator) 17 | { 18 | double area1, area2; 19 | area1 = calculator.CalcArea(rectangle); 20 | 21 | rectangle.SetWidth(rectangle.GetWidth() * 2); 22 | area2 = calculator.CalcArea(rectangle); 23 | 24 | // Test ok 25 | if (area2 == area1 * 2) 26 | return; 27 | 28 | // If test fails, throw exception 29 | throw new Exception("Test failed! Expected " + area1 + ", got " + area2); 30 | } 31 | 32 | private static void Main(string[] args) 33 | { 34 | ICalculator c = new Calculator(); 35 | // Test Rectangle #1 36 | IRectangle r = new Rectangle(4, 5); 37 | TestDoubleArea(r, c); 38 | 39 | // Test Rectangle #2 40 | r = new Rectangle(2, 8); 41 | TestDoubleArea(r, c); 42 | 43 | // Test Square #1 44 | r = new Square(4); 45 | TestDoubleArea(r, c); 46 | 47 | // Test Square #2 48 | r = new Square(2); 49 | TestDoubleArea(r, c); 50 | } 51 | } -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares/OfRectanglesAndSquares/Rectangle.cs: -------------------------------------------------------------------------------- 1 | namespace OfRectanglesAndSquares 2 | { 3 | /// 4 | /// This class handles the status of a Rectangle 5 | /// TODO add Interface 6 | /// 7 | public class Rectangle : IRectangle 8 | { 9 | private double _height; 10 | private double _width; 11 | 12 | public virtual void SetHeight(double height) 13 | { 14 | this._height = height; 15 | } 16 | 17 | public virtual void SetWidth(double width) 18 | { 19 | this._width = width; 20 | } 21 | 22 | public virtual double GetWidth() 23 | { 24 | return this._width; 25 | } 26 | 27 | public virtual double GetHeight() 28 | { 29 | return this._height; 30 | } 31 | 32 | public Rectangle(double height, double width) 33 | { 34 | this._height = height; 35 | this._width = width; 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares/OfRectanglesAndSquares/RectangleWithRound.cs: -------------------------------------------------------------------------------- 1 | namespace OfRectanglesAndSquares 2 | { 3 | /// 4 | /// This class rounds Rectangle height and width on sets to the ceiling integer 5 | /// 6 | public class RectangleWithRound : Rectangle 7 | { 8 | public RectangleWithRound(double height, double width) : base(height, width) 9 | { 10 | } 11 | 12 | public override void SetHeight(double height) 13 | { 14 | base.SetHeight(Math.Ceiling(height)); 15 | } 16 | 17 | public override void SetWidth(double width) 18 | { 19 | base.SetWidth(Math.Ceiling(width)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Code/OfRectanglesAndSquares/OfRectanglesAndSquares/Square.cs: -------------------------------------------------------------------------------- 1 | namespace OfRectanglesAndSquares 2 | { 3 | /// 4 | /// This class stores the status of a Square object 5 | /// 6 | public class Square : Rectangle 7 | { 8 | public override void SetWidth(double width) 9 | { 10 | base.SetWidth(width); 11 | base.SetHeight(width); 12 | } 13 | 14 | public override void SetHeight(double height) 15 | { 16 | base.SetHeight(height); 17 | base.SetWidth(height); 18 | } 19 | 20 | public Square(double side) : base(side, side) 21 | { 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | WebSvc 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jem.workbench.JavaEMFNature 26 | org.eclipse.wst.common.modulecore.ModuleCoreNature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | org.eclipse.jdt.core.javanature 29 | org.eclipse.wst.jsdt.core.jsNature 30 | 31 | 32 | 33 | 1746438638160 34 | 35 | 30 36 | 37 | org.eclipse.core.resources.regexFilterMatcher 38 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 3 | org.eclipse.jdt.core.compiler.compliance=21 4 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 5 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 8 | org.eclipse.jdt.core.compiler.release=enabled 9 | org.eclipse.jdt.core.compiler.source=21 10 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /Code/WebSvc.Java/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /Code/WebSvc.Java/lib/javax.servlet-api-4.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/WebSvc.Java/lib/javax.servlet-api-4.0.1.jar -------------------------------------------------------------------------------- /Code/WebSvc.Java/lib/json-20250107.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Code/WebSvc.Java/lib/json-20250107.jar -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/models/Person.java: -------------------------------------------------------------------------------- 1 | package models; 2 | 3 | /** 4 | * A Bean that models a User of our system 5 | */ 6 | public class Person { 7 | 8 | private int _id; 9 | private int _age; 10 | 11 | public int getId() { 12 | return _id; 13 | } 14 | 15 | public void setId(int id) { 16 | this._id = id; 17 | } 18 | 19 | public int getAge() { 20 | return _age; 21 | } 22 | 23 | public void setAge(int age) { 24 | this._age = age; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/repositories/IDb.java: -------------------------------------------------------------------------------- 1 | package repositories; 2 | 3 | import models.Person; 4 | 5 | /** 6 | * Interface to persistence layer 7 | */ 8 | public interface IDb { 9 | 10 | /** 11 | * Old, non CLEAN 12 | * @param key 13 | * @param age 14 | * @throws Exception 15 | */ 16 | void updateBirth(int key, int age) throws Exception; 17 | 18 | /** 19 | * Update birth date of a person in DB 20 | * @param p 21 | * @throws Exception 22 | */ 23 | void updateBirth(Person p) throws Exception; 24 | } 25 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/repositories/InMemoryDb.java: -------------------------------------------------------------------------------- 1 | package repositories; 2 | 3 | import java.util.Dictionary; 4 | import java.util.Hashtable; 5 | 6 | import models.Person; 7 | 8 | /** 9 | * For local testing. Does not persist. 10 | */ 11 | public class InMemoryDb implements IDb { 12 | 13 | private Dictionary _db = new Hashtable<>(); 14 | 15 | public InMemoryDb() { 16 | // Seeding for test... 17 | // TODO shall this stay here? 18 | _db.put(11, 25); 19 | } 20 | 21 | @Override 22 | public void updateBirth(int key, int age) throws Exception { 23 | if(_db.get(key) == null) 24 | throw new Exception("User with " + key + " does not exist!"); 25 | 26 | _db.put(key, age); 27 | } 28 | 29 | 30 | @Override 31 | public void updateBirth(Person p) throws Exception { 32 | if(_db.get(p.getId()) == null) 33 | throw new Exception("User with " + p.getId() + " does not exist!"); 34 | 35 | _db.put(p.getId(), p.getAge()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/repositories/MongoDB.java: -------------------------------------------------------------------------------- 1 | package repositories; 2 | 3 | import models.Person; 4 | 5 | /** 6 | * Mongo adapter 7 | */ 8 | public class MongoDB implements IDb { 9 | 10 | @Override 11 | public void updateBirth(Person p) throws Exception { 12 | throw new UnsupportedOperationException("Not yet implemented."); 13 | } 14 | 15 | @Override 16 | public void updateBirth(int key, int age) throws Exception { 17 | throw new UnsupportedOperationException("Not yet implemented."); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/services/IEnvironment.java: -------------------------------------------------------------------------------- 1 | package services; 2 | 3 | /** 4 | * Retrieve info on executing env 5 | */ 6 | public interface IEnvironment { 7 | Boolean IsLocal(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/services/IPersonaService.java: -------------------------------------------------------------------------------- 1 | package services; 2 | 3 | import models.Person; 4 | 5 | 6 | /** 7 | * Wrapper for business logics 8 | */ 9 | public interface IPersonaService { 10 | /** 11 | * Update age of a person in DB 12 | * @param p 13 | * @throws Exception 14 | */ 15 | void updateBirth(Person p) throws Exception; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/services/ISvcBuilder.java: -------------------------------------------------------------------------------- 1 | package services; 2 | 3 | import repositories.IDb; 4 | 5 | /** 6 | * Abstract factory for startup/boot svcs 7 | */ 8 | public interface ISvcBuilder { 9 | IDb createDb(); 10 | IPersonaService createPersonaService(); 11 | } 12 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/services/PersonaService.java: -------------------------------------------------------------------------------- 1 | package services; 2 | 3 | import models.Person; 4 | import repositories.IDb; 5 | 6 | /** 7 | * Service that handles business logic 8 | */ 9 | public class PersonaService implements IPersonaService { 10 | 11 | private IDb _myDb = null; 12 | 13 | public PersonaService(IDb db) { 14 | this._myDb = db; 15 | } 16 | 17 | public void updateBirth(Person p) throws Exception { 18 | 19 | // Business logic: check if age format is legal (e.g., >0), etc 20 | 21 | this._myDb.updateBirth(p); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/services/ServiceBuilder.java: -------------------------------------------------------------------------------- 1 | package services; 2 | 3 | import repositories.IDb; 4 | import repositories.InMemoryDb; 5 | import repositories.MongoDB; 6 | 7 | /** 8 | * Implementation for Local and PROD env 9 | */ 10 | public class ServiceBuilder implements ISvcBuilder { 11 | 12 | private static ServiceBuilder _instance = null; 13 | private IEnvironment _env = null; 14 | 15 | private ServiceBuilder() { 16 | 17 | // TODO we will see how this is handled by a MW... 18 | this._env = new TheEnvironment(); 19 | } 20 | 21 | public static ISvcBuilder GetInstance() { 22 | if(_instance == null) 23 | _instance = new ServiceBuilder(); 24 | 25 | return _instance; 26 | } 27 | 28 | @Override 29 | public IDb createDb() { 30 | if(_env.IsLocal()) 31 | return new InMemoryDb(); 32 | return new MongoDB(); 33 | } 34 | 35 | @Override 36 | public IPersonaService createPersonaService() { 37 | return new PersonaService(createDb()); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/services/TheEnvironment.java: -------------------------------------------------------------------------------- 1 | package services; 2 | 3 | /** 4 | * 5 | */ 6 | public class TheEnvironment implements IEnvironment{ 7 | 8 | @Override 9 | public Boolean IsLocal() { 10 | // TODO Read this by configuration file... 11 | return true; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/unitTests/MockThatThrowsException.java: -------------------------------------------------------------------------------- 1 | package unitTests; 2 | 3 | import models.Person; 4 | import repositories.IDb; 5 | 6 | /** 7 | * Testing for DB always throwing exception 8 | */ 9 | public class MockThatThrowsException implements IDb { 10 | 11 | @Override 12 | public void updateBirth(Person p) throws Exception { 13 | throw new Exception("User with " + p.getId() + " does not exist!"); 14 | 15 | } 16 | 17 | @Override 18 | public void updateBirth(int key, int age) throws Exception { 19 | throw new Exception("User with " + key + " does not exist!"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/unitTests/MyHttpServletRequest.java: -------------------------------------------------------------------------------- 1 | package unitTests; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.StringReader; 6 | import java.io.UnsupportedEncodingException; 7 | import java.security.Principal; 8 | import java.util.Collection; 9 | import java.util.Dictionary; 10 | import java.util.Enumeration; 11 | import java.util.Hashtable; 12 | import java.util.Locale; 13 | import java.util.Map; 14 | 15 | import javax.servlet.AsyncContext; 16 | import javax.servlet.DispatcherType; 17 | import javax.servlet.RequestDispatcher; 18 | import javax.servlet.ServletContext; 19 | import javax.servlet.ServletException; 20 | import javax.servlet.ServletInputStream; 21 | import javax.servlet.ServletRequest; 22 | import javax.servlet.ServletResponse; 23 | import javax.servlet.http.Cookie; 24 | import javax.servlet.http.HttpServletRequest; 25 | import javax.servlet.http.HttpServletResponse; 26 | import javax.servlet.http.HttpSession; 27 | import javax.servlet.http.HttpUpgradeHandler; 28 | import javax.servlet.http.Part; 29 | 30 | /** 31 | * Support for UnitTests 32 | */ 33 | public class MyHttpServletRequest implements HttpServletRequest { 34 | 35 | private Dictionary _params = new Hashtable<>(); 36 | private String _body = null; 37 | 38 | // These methods are mine 39 | public void setParameter(String key, String val) { 40 | this._params.put(key, val); 41 | } 42 | 43 | public void setBody(String s) { 44 | this._body = s; 45 | } 46 | 47 | @Override 48 | public AsyncContext getAsyncContext() { 49 | // TODO Auto-generated method stub 50 | return null; 51 | } 52 | 53 | @Override 54 | public Object getAttribute(String name) { 55 | // TODO Auto-generated method stub 56 | return null; 57 | } 58 | 59 | @Override 60 | public Enumeration getAttributeNames() { 61 | // TODO Auto-generated method stub 62 | return null; 63 | } 64 | 65 | @Override 66 | public String getCharacterEncoding() { 67 | // TODO Auto-generated method stub 68 | return null; 69 | } 70 | 71 | @Override 72 | public int getContentLength() { 73 | // TODO Auto-generated method stub 74 | return 0; 75 | } 76 | 77 | @Override 78 | public long getContentLengthLong() { 79 | // TODO Auto-generated method stub 80 | return 0; 81 | } 82 | 83 | @Override 84 | public String getContentType() { 85 | // TODO Auto-generated method stub 86 | return null; 87 | } 88 | 89 | @Override 90 | public DispatcherType getDispatcherType() { 91 | // TODO Auto-generated method stub 92 | return null; 93 | } 94 | 95 | @Override 96 | public ServletInputStream getInputStream() throws IOException { 97 | // TODO Auto-generated method stub 98 | return null; 99 | } 100 | 101 | @Override 102 | public String getLocalAddr() { 103 | // TODO Auto-generated method stub 104 | return null; 105 | } 106 | 107 | @Override 108 | public String getLocalName() { 109 | // TODO Auto-generated method stub 110 | return null; 111 | } 112 | 113 | @Override 114 | public int getLocalPort() { 115 | // TODO Auto-generated method stub 116 | return 0; 117 | } 118 | 119 | @Override 120 | public Locale getLocale() { 121 | // TODO Auto-generated method stub 122 | return null; 123 | } 124 | 125 | @Override 126 | public Enumeration getLocales() { 127 | // TODO Auto-generated method stub 128 | return null; 129 | } 130 | 131 | @Override 132 | public String getParameter(String name) { 133 | return this._params.get(name); 134 | } 135 | 136 | @Override 137 | public Map getParameterMap() { 138 | // TODO Auto-generated method stub 139 | return null; 140 | } 141 | 142 | @Override 143 | public Enumeration getParameterNames() { 144 | // TODO Auto-generated method stub 145 | return null; 146 | } 147 | 148 | @Override 149 | public String[] getParameterValues(String name) { 150 | // TODO Auto-generated method stub 151 | return null; 152 | } 153 | 154 | @Override 155 | public String getProtocol() { 156 | // TODO Auto-generated method stub 157 | return null; 158 | } 159 | 160 | @Override 161 | public BufferedReader getReader() throws IOException { 162 | return new BufferedReader(new StringReader(this._body)); 163 | } 164 | 165 | @Override 166 | public String getRealPath(String path) { 167 | // TODO Auto-generated method stub 168 | return null; 169 | } 170 | 171 | @Override 172 | public String getRemoteAddr() { 173 | // TODO Auto-generated method stub 174 | return null; 175 | } 176 | 177 | @Override 178 | public String getRemoteHost() { 179 | // TODO Auto-generated method stub 180 | return null; 181 | } 182 | 183 | @Override 184 | public int getRemotePort() { 185 | // TODO Auto-generated method stub 186 | return 0; 187 | } 188 | 189 | @Override 190 | public RequestDispatcher getRequestDispatcher(String path) { 191 | // TODO Auto-generated method stub 192 | return null; 193 | } 194 | 195 | @Override 196 | public String getScheme() { 197 | // TODO Auto-generated method stub 198 | return null; 199 | } 200 | 201 | @Override 202 | public String getServerName() { 203 | // TODO Auto-generated method stub 204 | return null; 205 | } 206 | 207 | @Override 208 | public int getServerPort() { 209 | // TODO Auto-generated method stub 210 | return 0; 211 | } 212 | 213 | @Override 214 | public ServletContext getServletContext() { 215 | // TODO Auto-generated method stub 216 | return null; 217 | } 218 | 219 | @Override 220 | public boolean isAsyncStarted() { 221 | // TODO Auto-generated method stub 222 | return false; 223 | } 224 | 225 | @Override 226 | public boolean isAsyncSupported() { 227 | // TODO Auto-generated method stub 228 | return false; 229 | } 230 | 231 | @Override 232 | public boolean isSecure() { 233 | // TODO Auto-generated method stub 234 | return false; 235 | } 236 | 237 | @Override 238 | public void removeAttribute(String name) { 239 | // TODO Auto-generated method stub 240 | 241 | } 242 | 243 | @Override 244 | public void setAttribute(String name, Object o) { 245 | // TODO Auto-generated method stub 246 | 247 | } 248 | 249 | @Override 250 | public void setCharacterEncoding(String env) throws UnsupportedEncodingException { 251 | // TODO Auto-generated method stub 252 | 253 | } 254 | 255 | @Override 256 | public AsyncContext startAsync() throws IllegalStateException { 257 | // TODO Auto-generated method stub 258 | return null; 259 | } 260 | 261 | @Override 262 | public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) 263 | throws IllegalStateException { 264 | // TODO Auto-generated method stub 265 | return null; 266 | } 267 | 268 | @Override 269 | public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { 270 | // TODO Auto-generated method stub 271 | return false; 272 | } 273 | 274 | @Override 275 | public String changeSessionId() { 276 | // TODO Auto-generated method stub 277 | return null; 278 | } 279 | 280 | @Override 281 | public String getAuthType() { 282 | // TODO Auto-generated method stub 283 | return null; 284 | } 285 | 286 | @Override 287 | public String getContextPath() { 288 | // TODO Auto-generated method stub 289 | return null; 290 | } 291 | 292 | @Override 293 | public Cookie[] getCookies() { 294 | // TODO Auto-generated method stub 295 | return null; 296 | } 297 | 298 | @Override 299 | public long getDateHeader(String name) { 300 | // TODO Auto-generated method stub 301 | return 0; 302 | } 303 | 304 | @Override 305 | public String getHeader(String name) { 306 | // TODO Auto-generated method stub 307 | return null; 308 | } 309 | 310 | @Override 311 | public Enumeration getHeaderNames() { 312 | // TODO Auto-generated method stub 313 | return null; 314 | } 315 | 316 | @Override 317 | public Enumeration getHeaders(String name) { 318 | // TODO Auto-generated method stub 319 | return null; 320 | } 321 | 322 | @Override 323 | public int getIntHeader(String name) { 324 | // TODO Auto-generated method stub 325 | return 0; 326 | } 327 | 328 | @Override 329 | public String getMethod() { 330 | // TODO Auto-generated method stub 331 | return null; 332 | } 333 | 334 | @Override 335 | public Part getPart(String name) throws IOException, ServletException { 336 | // TODO Auto-generated method stub 337 | return null; 338 | } 339 | 340 | @Override 341 | public Collection getParts() throws IOException, ServletException { 342 | // TODO Auto-generated method stub 343 | return null; 344 | } 345 | 346 | @Override 347 | public String getPathInfo() { 348 | // TODO Auto-generated method stub 349 | return null; 350 | } 351 | 352 | @Override 353 | public String getPathTranslated() { 354 | // TODO Auto-generated method stub 355 | return null; 356 | } 357 | 358 | @Override 359 | public String getQueryString() { 360 | // TODO Auto-generated method stub 361 | return null; 362 | } 363 | 364 | @Override 365 | public String getRemoteUser() { 366 | // TODO Auto-generated method stub 367 | return null; 368 | } 369 | 370 | @Override 371 | public String getRequestURI() { 372 | // TODO Auto-generated method stub 373 | return null; 374 | } 375 | 376 | @Override 377 | public StringBuffer getRequestURL() { 378 | // TODO Auto-generated method stub 379 | return null; 380 | } 381 | 382 | @Override 383 | public String getRequestedSessionId() { 384 | // TODO Auto-generated method stub 385 | return null; 386 | } 387 | 388 | @Override 389 | public String getServletPath() { 390 | // TODO Auto-generated method stub 391 | return null; 392 | } 393 | 394 | @Override 395 | public HttpSession getSession() { 396 | // TODO Auto-generated method stub 397 | return null; 398 | } 399 | 400 | @Override 401 | public HttpSession getSession(boolean create) { 402 | // TODO Auto-generated method stub 403 | return null; 404 | } 405 | 406 | @Override 407 | public Principal getUserPrincipal() { 408 | // TODO Auto-generated method stub 409 | return null; 410 | } 411 | 412 | @Override 413 | public boolean isRequestedSessionIdFromCookie() { 414 | // TODO Auto-generated method stub 415 | return false; 416 | } 417 | 418 | @Override 419 | public boolean isRequestedSessionIdFromURL() { 420 | // TODO Auto-generated method stub 421 | return false; 422 | } 423 | 424 | @Override 425 | public boolean isRequestedSessionIdFromUrl() { 426 | // TODO Auto-generated method stub 427 | return false; 428 | } 429 | 430 | @Override 431 | public boolean isRequestedSessionIdValid() { 432 | // TODO Auto-generated method stub 433 | return false; 434 | } 435 | 436 | @Override 437 | public boolean isUserInRole(String role) { 438 | // TODO Auto-generated method stub 439 | return false; 440 | } 441 | 442 | @Override 443 | public void login(String username, String password) throws ServletException { 444 | // TODO Auto-generated method stub 445 | 446 | } 447 | 448 | @Override 449 | public void logout() throws ServletException { 450 | // TODO Auto-generated method stub 451 | 452 | } 453 | 454 | @Override 455 | public T upgrade(Class handlerClass) throws IOException, ServletException { 456 | // TODO Auto-generated method stub 457 | return null; 458 | } 459 | 460 | } 461 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/unitTests/MyHttpServletResponse.java: -------------------------------------------------------------------------------- 1 | package unitTests; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.Collection; 6 | import java.util.Locale; 7 | 8 | import javax.servlet.ServletOutputStream; 9 | import javax.servlet.http.Cookie; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | /** 13 | * Support for UnitTests 14 | */ 15 | public class MyHttpServletResponse implements HttpServletResponse { 16 | 17 | private int _status; 18 | 19 | @Override 20 | public void flushBuffer() throws IOException { 21 | // TODO Auto-generated method stub 22 | 23 | } 24 | 25 | @Override 26 | public int getBufferSize() { 27 | // TODO Auto-generated method stub 28 | return 0; 29 | } 30 | 31 | @Override 32 | public String getCharacterEncoding() { 33 | // TODO Auto-generated method stub 34 | return null; 35 | } 36 | 37 | @Override 38 | public String getContentType() { 39 | // TODO Auto-generated method stub 40 | return null; 41 | } 42 | 43 | @Override 44 | public Locale getLocale() { 45 | // TODO Auto-generated method stub 46 | return null; 47 | } 48 | 49 | @Override 50 | public ServletOutputStream getOutputStream() throws IOException { 51 | // TODO Auto-generated method stub 52 | return null; 53 | } 54 | 55 | @Override 56 | public PrintWriter getWriter() throws IOException { 57 | // TODO Auto-generated method stub 58 | return null; 59 | } 60 | 61 | @Override 62 | public boolean isCommitted() { 63 | // TODO Auto-generated method stub 64 | return false; 65 | } 66 | 67 | @Override 68 | public void reset() { 69 | // TODO Auto-generated method stub 70 | 71 | } 72 | 73 | @Override 74 | public void resetBuffer() { 75 | // TODO Auto-generated method stub 76 | 77 | } 78 | 79 | @Override 80 | public void setBufferSize(int arg0) { 81 | // TODO Auto-generated method stub 82 | 83 | } 84 | 85 | @Override 86 | public void setCharacterEncoding(String charset) { 87 | // TODO Auto-generated method stub 88 | 89 | } 90 | 91 | @Override 92 | public void setContentLength(int len) { 93 | // TODO Auto-generated method stub 94 | 95 | } 96 | 97 | @Override 98 | public void setContentLengthLong(long len) { 99 | // TODO Auto-generated method stub 100 | 101 | } 102 | 103 | @Override 104 | public void setContentType(String type) { 105 | // TODO Auto-generated method stub 106 | 107 | } 108 | 109 | @Override 110 | public void setLocale(Locale loc) { 111 | // TODO Auto-generated method stub 112 | 113 | } 114 | 115 | @Override 116 | public void addCookie(Cookie cookie) { 117 | // TODO Auto-generated method stub 118 | 119 | } 120 | 121 | @Override 122 | public void addDateHeader(String name, long date) { 123 | // TODO Auto-generated method stub 124 | 125 | } 126 | 127 | @Override 128 | public void addHeader(String name, String value) { 129 | // TODO Auto-generated method stub 130 | 131 | } 132 | 133 | @Override 134 | public void addIntHeader(String name, int value) { 135 | // TODO Auto-generated method stub 136 | 137 | } 138 | 139 | @Override 140 | public boolean containsHeader(String name) { 141 | // TODO Auto-generated method stub 142 | return false; 143 | } 144 | 145 | @Override 146 | public String encodeRedirectURL(String url) { 147 | // TODO Auto-generated method stub 148 | return null; 149 | } 150 | 151 | @Override 152 | public String encodeRedirectUrl(String url) { 153 | // TODO Auto-generated method stub 154 | return null; 155 | } 156 | 157 | @Override 158 | public String encodeURL(String url) { 159 | // TODO Auto-generated method stub 160 | return null; 161 | } 162 | 163 | @Override 164 | public String encodeUrl(String url) { 165 | // TODO Auto-generated method stub 166 | return null; 167 | } 168 | 169 | @Override 170 | public String getHeader(String name) { 171 | // TODO Auto-generated method stub 172 | return null; 173 | } 174 | 175 | @Override 176 | public Collection getHeaderNames() { 177 | // TODO Auto-generated method stub 178 | return null; 179 | } 180 | 181 | @Override 182 | public Collection getHeaders(String name) { 183 | // TODO Auto-generated method stub 184 | return null; 185 | } 186 | 187 | @Override 188 | public int getStatus() { 189 | return this._status; 190 | } 191 | 192 | @Override 193 | public void sendError(int sc) throws IOException { 194 | // TODO Auto-generated method stub 195 | 196 | } 197 | 198 | @Override 199 | public void sendError(int sc, String msg) throws IOException { 200 | // TODO Auto-generated method stub 201 | 202 | } 203 | 204 | @Override 205 | public void sendRedirect(String location) throws IOException { 206 | // TODO Auto-generated method stub 207 | 208 | } 209 | 210 | @Override 211 | public void setDateHeader(String name, long date) { 212 | // TODO Auto-generated method stub 213 | 214 | } 215 | 216 | @Override 217 | public void setHeader(String name, String value) { 218 | // TODO Auto-generated method stub 219 | 220 | } 221 | 222 | @Override 223 | public void setIntHeader(String name, int value) { 224 | // TODO Auto-generated method stub 225 | 226 | } 227 | 228 | @Override 229 | public void setStatus(int sc) { 230 | this._status = sc; 231 | 232 | } 233 | 234 | @Override 235 | public void setStatus(int sc, String sm) { 236 | // TODO Auto-generated method stub 237 | 238 | } 239 | 240 | } 241 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/unitTests/MyServletTest.java: -------------------------------------------------------------------------------- 1 | package unitTests; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | 6 | import web.MyServlet; 7 | 8 | /** 9 | * Unit and integration tests 10 | */ 11 | public class MyServletTest { 12 | 13 | private static void AssertEquals(int expected, int actual) { 14 | if(expected != actual) { 15 | System.out.println("Assertion failed! Expected \'" + expected + "\', got \'"+ actual + "\' instead"); 16 | System.exit(-1); 17 | } 18 | } 19 | 20 | private static void AssertNull(Object o) { 21 | if(o != null) { 22 | System.out.println("Assertion failed! object is not null"); 23 | System.exit(-1); 24 | } 25 | } 26 | 27 | private static void MyServlet_DbThrowsException_Return400() { 28 | 29 | // Arrange 30 | 31 | // Mock svcbuilder 32 | ServicesBuilderForMocks svcBuilder = new ServicesBuilderForMocks(); 33 | 34 | // Mock up HttpServletRequest and HttpServletResponse 35 | MyHttpServletRequest request = new MyHttpServletRequest(); 36 | request.setParameter("id", "11"); 37 | request.setBody("{\"age\" : \"43\"}"); 38 | MyHttpServletResponse response = new MyHttpServletResponse(); 39 | 40 | // SUT stands for "Service Under Test" 41 | MyServlet sut = new MyServlet(svcBuilder.createPersonaService()); 42 | 43 | 44 | // Act 45 | 46 | Exception ioException = null; 47 | 48 | try { 49 | sut.doPost(request, response); 50 | } catch (IOException e) { 51 | ioException = e; 52 | } 53 | 54 | // Assert 55 | 56 | AssertNull(ioException); // Check we dit not capture a wrong type of Exception 57 | AssertEquals(response.getStatus(), 400); 58 | 59 | System.out.println("Test successful!"); 60 | } 61 | 62 | public static void main(String[] args) { 63 | MyServlet_DbThrowsException_Return400(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/unitTests/ServicesBuilderForMocks.java: -------------------------------------------------------------------------------- 1 | package unitTests; 2 | 3 | import repositories.IDb; 4 | import services.IPersonaService; 5 | import services.ISvcBuilder; 6 | import services.PersonaService; 7 | 8 | /** 9 | * For mocking tests 10 | */ 11 | public class ServicesBuilderForMocks implements ISvcBuilder { 12 | 13 | @Override 14 | public IDb createDb() { 15 | return new MockThatThrowsException(); 16 | } 17 | 18 | @Override 19 | public IPersonaService createPersonaService() { 20 | return new PersonaService(createDb()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/utils/Mapper.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import org.json.JSONObject; 4 | 5 | import models.Person; 6 | 7 | 8 | /** 9 | * Mappers between datatypes are implemented here 10 | */ 11 | public class Mapper { 12 | 13 | 14 | public static Person mapToPerson(int id, JSONObject jsonObject) { 15 | String ageStr = jsonObject.getString("age"); 16 | 17 | Person p = new Person(); 18 | p.setId(id); 19 | p.setAge(Integer.parseInt(ageStr)); 20 | 21 | return p; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/utils/WebUtils.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | import org.json.JSONObject; 9 | 10 | /** 11 | * Useful stuff for parsing Web requests/datatypes 12 | */ 13 | public class WebUtils { 14 | 15 | public static JSONObject getHttpRequestBodyAsJson(HttpServletRequest request) throws IOException { 16 | StringBuilder requestBody = new StringBuilder(); 17 | String line; 18 | try (BufferedReader reader = request.getReader()) { 19 | while ((line = reader.readLine()) != null) { 20 | requestBody.append(line).append("\n"); 21 | } 22 | } 23 | return new JSONObject(requestBody.toString()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/web/MyServlet.java: -------------------------------------------------------------------------------- 1 | package web; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.annotation.WebServlet; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.json.JSONException; 11 | import org.json.JSONObject; 12 | 13 | import models.Person; 14 | import services.IPersonaService; 15 | import services.ServiceBuilder; 16 | import utils.Mapper; 17 | import utils.WebUtils; 18 | 19 | /** 20 | * Servlet implementation class MyServlet 21 | */ 22 | @WebServlet("/MyServlet") 23 | public class MyServlet extends HttpServlet { 24 | private static final long serialVersionUID = 1L; 25 | private IPersonaService _personaSvc = null; 26 | /** 27 | * @see HttpServlet#HttpServlet() 28 | */ 29 | public MyServlet() { 30 | this(ServiceBuilder.GetInstance().createPersonaService()); 31 | } 32 | 33 | /** 34 | * Explicitly assign svcBuilder. This is used for testing. 35 | * We'll see how this is handled in Middleware... 36 | * @param svcBuilder 37 | */ 38 | public MyServlet(IPersonaService personaSvc) { 39 | super(); 40 | 41 | this._personaSvc = personaSvc; 42 | } 43 | 44 | /** 45 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 46 | */ 47 | public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { 48 | 49 | int id = Integer.parseInt(request.getParameter("id")); 50 | 51 | 52 | JSONObject jsonObject = null; 53 | try { 54 | jsonObject = WebUtils.getHttpRequestBodyAsJson(request); 55 | } catch (JSONException e) { 56 | response.getWriter().append(e.getMessage() + "\n" + e.getStackTrace().toString()); 57 | return; 58 | } 59 | 60 | Person p = Mapper.mapToPerson(id, jsonObject); 61 | 62 | try { 63 | this._personaSvc.updateBirth(p); 64 | } 65 | catch (Exception e) { 66 | response.setStatus(400); 67 | } 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/java/web/MyServletNoClean.java: -------------------------------------------------------------------------------- 1 | package web; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import org.json.JSONException; 12 | import org.json.JSONObject; 13 | 14 | import repositories.IDb; 15 | import services.ISvcBuilder; 16 | import services.ServiceBuilder; 17 | 18 | public class MyServletNoClean extends HttpServlet { 19 | private static final long serialVersionUID = 1L; 20 | 21 | private IDb _myDb = null; 22 | 23 | /** 24 | * @see HttpServlet#HttpServlet() 25 | */ 26 | public MyServletNoClean() { 27 | this(ServiceBuilder.GetInstance()); 28 | } 29 | 30 | /** 31 | * Explicitly assign svcBuilder. This is used for testing. 32 | * We'll see how this is handled in Middleware... 33 | * @param svcBuilder 34 | */ 35 | public MyServletNoClean(ISvcBuilder svcBuilder) { 36 | super(); 37 | 38 | this._myDb = svcBuilder.createDb(); 39 | } 40 | 41 | /** 42 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 43 | */ 44 | public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 45 | 46 | int id = Integer.parseInt(request.getParameter("id")); 47 | int age = Integer.parseInt(request.getParameter("age")); 48 | 49 | try { 50 | this._myDb.updateBirth(id, age); 51 | } 52 | catch (Exception e) { 53 | // Return Http code 400 54 | response.setStatus(401); // This is wrong on purpose! 55 | } 56 | } 57 | 58 | /** 59 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 60 | */ 61 | public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 62 | 63 | int id = Integer.parseInt(request.getParameter("id")); 64 | 65 | 66 | StringBuilder requestBody = new StringBuilder(); 67 | String line; 68 | try (BufferedReader reader = request.getReader()) { 69 | while ((line = reader.readLine()) != null) { 70 | requestBody.append(line).append("\n"); 71 | } 72 | } 73 | 74 | JSONObject jsonObject = null; 75 | try { 76 | jsonObject = new JSONObject(requestBody.toString()); 77 | } catch (JSONException e) { 78 | response.getWriter().append(e.getMessage() + "\n" + e.getStackTrace().toString()); 79 | return; 80 | } 81 | 82 | String ageStr = jsonObject.getString("age"); 83 | int age = Integer.parseInt(ageStr); 84 | // Business logic: check if age format is legal (e.g., >0), etc 85 | try { 86 | this._myDb.updateBirth(id, age); 87 | } 88 | catch (Exception e) { 89 | response.setStatus(400); 90 | } 91 | } 92 | 93 | } -------------------------------------------------------------------------------- /Code/WebSvc.Java/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | # but not Directory.Build.rsp, as it configures directory-level build defaults 86 | !Directory.Build.rsp 87 | *.sbr 88 | *.tlb 89 | *.tli 90 | *.tlh 91 | *.tmp 92 | *.tmp_proj 93 | *_wpftmp.csproj 94 | *.log 95 | *.tlog 96 | *.vspscc 97 | *.vssscc 98 | .builds 99 | *.pidb 100 | *.svclog 101 | *.scc 102 | 103 | # Chutzpah Test files 104 | _Chutzpah* 105 | 106 | # Visual C++ cache files 107 | ipch/ 108 | *.aps 109 | *.ncb 110 | *.opendb 111 | *.opensdf 112 | *.sdf 113 | *.cachefile 114 | *.VC.db 115 | *.VC.VC.opendb 116 | 117 | # Visual Studio profiler 118 | *.psess 119 | *.vsp 120 | *.vspx 121 | *.sap 122 | 123 | # Visual Studio Trace Files 124 | *.e2e 125 | 126 | # TFS 2012 Local Workspace 127 | $tf/ 128 | 129 | # Guidance Automation Toolkit 130 | *.gpState 131 | 132 | # ReSharper is a .NET coding add-in 133 | _ReSharper*/ 134 | *.[Rr]e[Ss]harper 135 | *.DotSettings.user 136 | 137 | # TeamCity is a build add-in 138 | _TeamCity* 139 | 140 | # DotCover is a Code Coverage Tool 141 | *.dotCover 142 | 143 | # AxoCover is a Code Coverage Tool 144 | .axoCover/* 145 | !.axoCover/settings.json 146 | 147 | # Coverlet is a free, cross platform Code Coverage Tool 148 | coverage*.json 149 | coverage*.xml 150 | coverage*.info 151 | 152 | # Visual Studio code coverage results 153 | *.coverage 154 | *.coveragexml 155 | 156 | # NCrunch 157 | _NCrunch_* 158 | .*crunch*.local.xml 159 | nCrunchTemp_* 160 | 161 | # MightyMoose 162 | *.mm.* 163 | AutoTest.Net/ 164 | 165 | # Web workbench (sass) 166 | .sass-cache/ 167 | 168 | # Installshield output folder 169 | [Ee]xpress/ 170 | 171 | # DocProject is a documentation generator add-in 172 | DocProject/buildhelp/ 173 | DocProject/Help/*.HxT 174 | DocProject/Help/*.HxC 175 | DocProject/Help/*.hhc 176 | DocProject/Help/*.hhk 177 | DocProject/Help/*.hhp 178 | DocProject/Help/Html2 179 | DocProject/Help/html 180 | 181 | # Click-Once directory 182 | publish/ 183 | 184 | # Publish Web Output 185 | *.[Pp]ublish.xml 186 | *.azurePubxml 187 | # Note: Comment the next line if you want to checkin your web deploy settings, 188 | # but database connection strings (with potential passwords) will be unencrypted 189 | *.pubxml 190 | *.publishproj 191 | 192 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 193 | # checkin your Azure Web App publish settings, but sensitive information contained 194 | # in these scripts will be unencrypted 195 | PublishScripts/ 196 | 197 | # NuGet Packages 198 | *.nupkg 199 | # NuGet Symbol Packages 200 | *.snupkg 201 | # The packages folder can be ignored because of Package Restore 202 | **/[Pp]ackages/* 203 | # except build/, which is used as an MSBuild target. 204 | !**/[Pp]ackages/build/ 205 | # Uncomment if necessary however generally it will be regenerated when needed 206 | #!**/[Pp]ackages/repositories.config 207 | # NuGet v3's project.json files produces more ignorable files 208 | *.nuget.props 209 | *.nuget.targets 210 | 211 | # Microsoft Azure Build Output 212 | csx/ 213 | *.build.csdef 214 | 215 | # Microsoft Azure Emulator 216 | ecf/ 217 | rcf/ 218 | 219 | # Windows Store app package directories and files 220 | AppPackages/ 221 | BundleArtifacts/ 222 | Package.StoreAssociation.xml 223 | _pkginfo.txt 224 | *.appx 225 | *.appxbundle 226 | *.appxupload 227 | 228 | # Visual Studio cache files 229 | # files ending in .cache can be ignored 230 | *.[Cc]ache 231 | # but keep track of directories ending in .cache 232 | !?*.[Cc]ache/ 233 | 234 | # Others 235 | ClientBin/ 236 | ~$* 237 | *~ 238 | *.dbmdl 239 | *.dbproj.schemaview 240 | *.jfm 241 | *.pfx 242 | *.publishsettings 243 | orleans.codegen.cs 244 | 245 | # Including strong name files can present a security risk 246 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 247 | #*.snk 248 | 249 | # Since there are multiple workflows, uncomment next line to ignore bower_components 250 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 251 | #bower_components/ 252 | 253 | # RIA/Silverlight projects 254 | Generated_Code/ 255 | 256 | # Backup & report files from converting an old project file 257 | # to a newer Visual Studio version. Backup files are not needed, 258 | # because we have git ;-) 259 | _UpgradeReport_Files/ 260 | Backup*/ 261 | UpgradeLog*.XML 262 | UpgradeLog*.htm 263 | ServiceFabricBackup/ 264 | *.rptproj.bak 265 | 266 | # SQL Server files 267 | *.mdf 268 | *.ldf 269 | *.ndf 270 | 271 | # Business Intelligence projects 272 | *.rdl.data 273 | *.bim.layout 274 | *.bim_*.settings 275 | *.rptproj.rsuser 276 | *- [Bb]ackup.rdl 277 | *- [Bb]ackup ([0-9]).rdl 278 | *- [Bb]ackup ([0-9][0-9]).rdl 279 | 280 | # Microsoft Fakes 281 | FakesAssemblies/ 282 | 283 | # GhostDoc plugin setting file 284 | *.GhostDoc.xml 285 | 286 | # Node.js Tools for Visual Studio 287 | .ntvs_analysis.dat 288 | node_modules/ 289 | 290 | # Visual Studio 6 build log 291 | *.plg 292 | 293 | # Visual Studio 6 workspace options file 294 | *.opt 295 | 296 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 297 | *.vbw 298 | 299 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 300 | *.vbp 301 | 302 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 303 | *.dsw 304 | *.dsp 305 | 306 | # Visual Studio 6 technical files 307 | *.ncb 308 | *.aps 309 | 310 | # Visual Studio LightSwitch build output 311 | **/*.HTMLClient/GeneratedArtifacts 312 | **/*.DesktopClient/GeneratedArtifacts 313 | **/*.DesktopClient/ModelManifest.xml 314 | **/*.Server/GeneratedArtifacts 315 | **/*.Server/ModelManifest.xml 316 | _Pvt_Extensions 317 | 318 | # Paket dependency manager 319 | .paket/paket.exe 320 | paket-files/ 321 | 322 | # FAKE - F# Make 323 | .fake/ 324 | 325 | # CodeRush personal settings 326 | .cr/personal 327 | 328 | # Python Tools for Visual Studio (PTVS) 329 | __pycache__/ 330 | *.pyc 331 | 332 | # Cake - Uncomment if you are using it 333 | # tools/** 334 | # !tools/packages.config 335 | 336 | # Tabs Studio 337 | *.tss 338 | 339 | # Telerik's JustMock configuration file 340 | *.jmconfig 341 | 342 | # BizTalk build output 343 | *.btp.cs 344 | *.btm.cs 345 | *.odx.cs 346 | *.xsd.cs 347 | 348 | # OpenCover UI analysis results 349 | OpenCover/ 350 | 351 | # Azure Stream Analytics local run output 352 | ASALocalRun/ 353 | 354 | # MSBuild Binary and Structured Log 355 | *.binlog 356 | 357 | # NVidia Nsight GPU debugger configuration file 358 | *.nvuser 359 | 360 | # MFractors (Xamarin productivity tool) working folder 361 | .mfractor/ 362 | 363 | # Local History for Visual Studio 364 | .localhistory/ 365 | 366 | # Visual Studio History (VSHistory) files 367 | .vshistory/ 368 | 369 | # BeatPulse healthcheck temp database 370 | healthchecksdb 371 | 372 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 373 | MigrationBackup/ 374 | 375 | # Ionide (cross platform F# VS Code tools) working folder 376 | .ionide/ 377 | 378 | # Fody - auto-generated XML schema 379 | FodyWeavers.xsd 380 | 381 | # VS Code files for those working on multiple tools 382 | .vscode/* 383 | !.vscode/settings.json 384 | !.vscode/tasks.json 385 | !.vscode/launch.json 386 | !.vscode/extensions.json 387 | *.code-workspace 388 | 389 | # Local History for Visual Studio Code 390 | .history/ 391 | 392 | # Windows Installer files from build outputs 393 | *.cab 394 | *.msi 395 | *.msix 396 | *.msm 397 | *.msp 398 | 399 | # JetBrains Rider 400 | *.sln.iml 401 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/Tests/Factories/TestApplicationFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.Testing; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using Microsoft.Extensions.DependencyInjection.Extensions; 4 | using Microsoft.Extensions.Hosting; 5 | using Repositories; 6 | using WebSvc.dotNet; 7 | 8 | namespace Tests.Factories 9 | { 10 | /// 11 | /// This class supports the creation of the testing environment 12 | /// 13 | internal class TestApplicationFactory : WebApplicationFactory 14 | { 15 | private readonly IDb _theDb; 16 | 17 | public TestApplicationFactory(IDb theDb) 18 | { 19 | _theDb = theDb; 20 | } 21 | 22 | /// 23 | /// Creates the webapplication, and the client 24 | /// 25 | /// 26 | /// 27 | public static HttpClient BuildFactoryAndClient(IDb userRepository) 28 | { 29 | var client = new TestApplicationFactory(userRepository) 30 | .CreateClient(new WebApplicationFactoryClientOptions() 31 | { 32 | BaseAddress = new Uri("https://localhost") 33 | }); 34 | 35 | return client; 36 | } 37 | 38 | /// 39 | /// Overrided method that creates our host 40 | /// 41 | /// 42 | /// 43 | protected override IHost CreateHost(IHostBuilder builder) 44 | { 45 | builder.ConfigureServices(services => 46 | { 47 | _ = services.BuildServiceProvider(); 48 | // Inject the IDb 49 | services.Replace(new ServiceDescriptor(typeof(IDb), _theDb)); 50 | }); 51 | 52 | return base.CreateHost(builder); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/Tests/MSTestSettings.cs: -------------------------------------------------------------------------------- 1 | [assembly: Parallelize(Scope = ExecutionScope.MethodLevel)] 2 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/Tests/Mocks/DbMockThatThrowsException.cs: -------------------------------------------------------------------------------- 1 | using Model; 2 | using Repositories; 3 | 4 | namespace Tests.Mocks 5 | { 6 | internal class DbMockThatThrowsException : IDb 7 | { 8 | public void UpdateBirth(int key, Person p) 9 | { 10 | throw new Exception("User with " + key + " does not exist!"); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/Tests/MySvcTests.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Controllers; 3 | using Dto; 4 | using Helpers; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Model; 8 | using Moq; 9 | using Repositories; 10 | using Tests.Factories; 11 | using Tests.Mocks; 12 | 13 | namespace Tests 14 | { 15 | /// 16 | /// Test MySvc both with HttpClient (e.g., implementing a real Http call) and with direct Fn call. 17 | /// The version with Http call has await/async semantics, which I haven't explained in the course. 18 | /// We also have a third variant using the Moq library. 19 | /// 20 | [TestClass] 21 | public sealed class MySvcTests 22 | { 23 | // Here we don't mock the Mapper 24 | private IMapper _mapper = default!; 25 | 26 | // Test data (this could also be in another "TestData" static class) 27 | private const int ValidId = 11; 28 | private static MySvcPostPayload ValidPayload = new MySvcPostPayload 29 | { 30 | Age = "43" 31 | }; 32 | 33 | private static string BuildRequestUrl(int? id) 34 | { 35 | return "/mysvc" + (id.HasValue ? $"?id={id}" : ""); 36 | } 37 | 38 | /// 39 | /// Common inits for tests 40 | /// 41 | [TestInitialize] 42 | public void TestInitialize() 43 | { 44 | // In these tests we use a fully working automapper 45 | _mapper = new MapperConfiguration(cfg => { cfg.AddProfile(); }).CreateMapper(); 46 | } 47 | 48 | /// 49 | /// Test full Http request to URL endpoint. This versin uses my handmade mock for DB. 50 | /// This returns a Task because of the await/async semantic. 51 | /// 52 | [TestMethod] 53 | public async Task HttpRequest_DbThrowsException_Return400() 54 | { 55 | // Arrange 56 | 57 | // Mock client. This fn also creates the server 58 | var client = TestApplicationFactory.BuildFactoryAndClient(new DbMockThatThrowsException()); 59 | 60 | // Act 61 | var response = await client.PostAsJsonAsync(BuildRequestUrl(ValidId), ValidPayload); 62 | 63 | // Assert 64 | Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode); 65 | } 66 | 67 | /// 68 | /// Test full Http request to URL endpoint. This versin uses my handmade mock for DB. 69 | /// This is the version 2 of my test, which uses the Mow library so we don't need to create a custom mock class. 70 | /// 71 | [TestMethod] 72 | public async Task HttpRequest_DbThrowsException_Return400_v2() 73 | { 74 | // Arrange 75 | 76 | // Create a mock for IDb using Moq 77 | var dbMock = new Moq.Mock(); 78 | dbMock.Setup(x => x.UpdateBirth(It.IsAny(), It.IsAny())) 79 | .Throws(new Exception($"User with {ValidId} does not exist!")); 80 | 81 | // Mock client. This fn also creates the server 82 | var client = TestApplicationFactory.BuildFactoryAndClient(dbMock.Object); 83 | 84 | // Act 85 | var response = await client.PostAsJsonAsync(BuildRequestUrl(ValidId), ValidPayload); 86 | 87 | // Assert 88 | Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode); 89 | } 90 | 91 | /// 92 | /// Here we test the direct call to the Post method. 93 | /// Note how we need to add scaffold code to create the internals of the HttpRequest objects, such as the HttpResponse. 94 | /// 95 | [TestMethod] 96 | public void MyServlet_DbThrowsException_Return400() 97 | { 98 | // Arrange 99 | 100 | // We need to make sure that no exception is thrown 101 | Exception ex = null!; 102 | 103 | // We also need to mock the HttpCtx, to properly initialize the "Response" object 104 | var mockCtx = new ControllerContext(); 105 | mockCtx.HttpContext = new DefaultHttpContext(); 106 | 107 | // SUT stands for "Service Under Test" 108 | var sut = new MySvcController(null!, // We don't use logger in this test 109 | new DbMockThatThrowsException(), // Use my mock for IDb 110 | _mapper // We are not mocking mapper, here 111 | ); 112 | sut.ControllerContext = mockCtx; 113 | 114 | // Act 115 | try 116 | { 117 | sut.Post(ValidId, ValidPayload); 118 | } 119 | catch (Exception e) 120 | { 121 | ex = e; 122 | } 123 | 124 | // Assert 125 | Assert.IsNull(ex); 126 | Assert.AreEqual(mockCtx.HttpContext.Response.StatusCode, 400); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/Tests/Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | latest 6 | enable 7 | enable 8 | true 9 | 2d4ec4d1-5701-4de7-90b4-dcb105ac4e90 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.14.36109.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebSvc.dotNet", "WebSvc.dotNet\WebSvc.dotNet.csproj", "{AE3837F2-DCEF-4856-9AAB-4305D9A924D7}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{B07DAB9E-E920-4C7E-A096-8F672036258B}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {AE3837F2-DCEF-4856-9AAB-4305D9A924D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {AE3837F2-DCEF-4856-9AAB-4305D9A924D7}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {AE3837F2-DCEF-4856-9AAB-4305D9A924D7}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {AE3837F2-DCEF-4856-9AAB-4305D9A924D7}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {B07DAB9E-E920-4C7E-A096-8F672036258B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {B07DAB9E-E920-4C7E-A096-8F672036258B}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {B07DAB9E-E920-4C7E-A096-8F672036258B}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {B07DAB9E-E920-4C7E-A096-8F672036258B}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {2C0F04D8-6D27-4D70-AAA3-8EA2B3DA8463} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/Controllers/MySvcController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Dto; 3 | using Repositories; 4 | using AutoMapper; 5 | using Model; 6 | 7 | namespace Controllers 8 | { 9 | [ApiController] 10 | [Route("[controller]")] 11 | public class MySvcController : ControllerBase 12 | { 13 | private readonly ILogger _logger; 14 | private readonly IDb _myDb; 15 | private readonly IMapper _mapper; 16 | 17 | public MySvcController(ILogger logger, IDb myDb, IMapper mapper) 18 | { 19 | _logger = logger; 20 | _myDb = myDb; 21 | _mapper = mapper; 22 | } 23 | 24 | [RequireHttps] 25 | [HttpPost] 26 | public void Post([System.Web.Http.FromUri] int id, [FromBody] MySvcPostPayload dto) 27 | { 28 | try 29 | { 30 | _myDb.UpdateBirth(id, _mapper.Map(dto)); 31 | } 32 | catch (Exception) 33 | { 34 | Response.StatusCode = 400; 35 | return; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/Dto/MySvcPostPayload.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using WebSvc.dotNet.Helpers; 3 | 4 | namespace Dto 5 | { 6 | public class MySvcPostPayload 7 | { 8 | [Required] 9 | [MyAgeValidator(maxVal:100)] 10 | //[Range(0,100)] 11 | public string Age { get; set; } = default!; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/Helpers/AutoMapperProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Dto; 3 | using Model; 4 | 5 | namespace Helpers 6 | { 7 | public class AutoMapperProfile : Profile 8 | { 9 | public AutoMapperProfile() 10 | { 11 | // Crate mappings 12 | 13 | CreateMap() 14 | .ForMember(d => d.Age, opt => opt.MapFrom(s => int.Parse(s.Age))); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/Helpers/MyAgeValidator.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace WebSvc.dotNet.Helpers 4 | { 5 | [AttributeUsage(AttributeTargets.Property)] 6 | 7 | public class MyAgeValidator : ValidationAttribute 8 | { 9 | private readonly int _maxVal; 10 | 11 | public MyAgeValidator(int maxVal) 12 | { 13 | _maxVal = maxVal; 14 | } 15 | 16 | public override bool IsValid(object? value) 17 | { 18 | if(value == null) return false; 19 | 20 | if (!int.TryParse(value.ToString(), out int v)) return false; 21 | 22 | if (v > _maxVal) return false; 23 | 24 | return true; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/Model/Person.cs: -------------------------------------------------------------------------------- 1 | namespace Model 2 | { 3 | public class Person 4 | { 5 | public int Age { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/Program.cs: -------------------------------------------------------------------------------- 1 | using Helpers; 2 | using Repositories; 3 | 4 | namespace WebSvc.dotNet 5 | { 6 | public class Program 7 | { 8 | private static void Main(string[] args) 9 | { 10 | var builder = WebApplication.CreateBuilder(args); 11 | 12 | // Add services to the container. 13 | 14 | builder.Services.AddControllers(); 15 | 16 | builder.Services.AddAutoMapper(cfg => { cfg.AddProfile(); }); 17 | 18 | if (builder.Environment.EnvironmentName == "Local") 19 | { 20 | builder.Services.AddSingleton(); 21 | } 22 | else 23 | builder.Services.AddSingleton(); 24 | 25 | 26 | var app = builder.Build(); 27 | 28 | // Configure the HTTP request pip 29 | 30 | app.UseHttpsRedirection(); 31 | 32 | app.UseAuthorization(); 33 | 34 | app.MapControllers(); 35 | 36 | app.Run(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "http": { 4 | "commandName": "Project", 5 | "launchBrowser": true, 6 | "launchUrl": "mysvc", 7 | "environmentVariables": { 8 | "ASPNETCORE_ENVIRONMENT": "Development" 9 | }, 10 | "dotnetRunMessages": true, 11 | "applicationUrl": "http://localhost:5041" 12 | }, 13 | "https": { 14 | "commandName": "Project", 15 | "launchBrowser": true, 16 | "launchUrl": "mysvc", 17 | "environmentVariables": { 18 | "ASPNETCORE_ENVIRONMENT": "Local" 19 | }, 20 | "dotnetRunMessages": true, 21 | "applicationUrl": "https://localhost:7079;http://localhost:5041" 22 | }, 23 | "IIS Express": { 24 | "commandName": "IISExpress", 25 | "launchBrowser": true, 26 | "launchUrl": "mysvc", 27 | "environmentVariables": { 28 | "ASPNETCORE_ENVIRONMENT": "Development" 29 | } 30 | } 31 | }, 32 | "$schema": "http://json.schemastore.org/launchsettings.json", 33 | "iisSettings": { 34 | "windowsAuthentication": false, 35 | "anonymousAuthentication": true, 36 | "iisExpress": { 37 | "applicationUrl": "http://localhost:51137", 38 | "sslPort": 44396 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/Repositories/IDb.cs: -------------------------------------------------------------------------------- 1 | using Model; 2 | 3 | namespace Repositories 4 | { 5 | public interface IDb 6 | { 7 | void UpdateBirth(int key, Person p); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/Repositories/InMemoryDb.cs: -------------------------------------------------------------------------------- 1 | using Model; 2 | 3 | namespace Repositories 4 | { 5 | public class InMemoryDb : IDb 6 | { 7 | public IDictionary _db = new Dictionary(); 8 | 9 | public InMemoryDb() 10 | { 11 | _db.Add(11, 25); 12 | } 13 | 14 | public void UpdateBirth(int key, Person p) 15 | { 16 | if (!_db.ContainsKey(key)) 17 | throw new Exception("User with " + key + " does not exist!"); 18 | 19 | _db[key] = p.Age; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/Repositories/MongoDb.cs: -------------------------------------------------------------------------------- 1 | using Model; 2 | 3 | namespace Repositories 4 | { 5 | public class MongoDb : IDb 6 | { 7 | public void UpdateBirth(int key, Person p) 8 | { 9 | // ... 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/WebSvc.dotNet.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/WebSvc.dotNet.http: -------------------------------------------------------------------------------- 1 | @WebSvc.dotNet_HostAddress = http://localhost:5041 2 | 3 | GET {{WebSvc.dotNet_HostAddress}}/mysvc/ 4 | Accept: application/json 5 | 6 | ### 7 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /Code/WebSvc.dotNet/WebSvc.dotNet/appsettings.local.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Code/WebSvc/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | # but not Directory.Build.rsp, as it configures directory-level build defaults 86 | !Directory.Build.rsp 87 | *.sbr 88 | *.tlb 89 | *.tli 90 | *.tlh 91 | *.tmp 92 | *.tmp_proj 93 | *_wpftmp.csproj 94 | *.log 95 | *.tlog 96 | *.vspscc 97 | *.vssscc 98 | .builds 99 | *.pidb 100 | *.svclog 101 | *.scc 102 | 103 | # Chutzpah Test files 104 | _Chutzpah* 105 | 106 | # Visual C++ cache files 107 | ipch/ 108 | *.aps 109 | *.ncb 110 | *.opendb 111 | *.opensdf 112 | *.sdf 113 | *.cachefile 114 | *.VC.db 115 | *.VC.VC.opendb 116 | 117 | # Visual Studio profiler 118 | *.psess 119 | *.vsp 120 | *.vspx 121 | *.sap 122 | 123 | # Visual Studio Trace Files 124 | *.e2e 125 | 126 | # TFS 2012 Local Workspace 127 | $tf/ 128 | 129 | # Guidance Automation Toolkit 130 | *.gpState 131 | 132 | # ReSharper is a .NET coding add-in 133 | _ReSharper*/ 134 | *.[Rr]e[Ss]harper 135 | *.DotSettings.user 136 | 137 | # TeamCity is a build add-in 138 | _TeamCity* 139 | 140 | # DotCover is a Code Coverage Tool 141 | *.dotCover 142 | 143 | # AxoCover is a Code Coverage Tool 144 | .axoCover/* 145 | !.axoCover/settings.json 146 | 147 | # Coverlet is a free, cross platform Code Coverage Tool 148 | coverage*.json 149 | coverage*.xml 150 | coverage*.info 151 | 152 | # Visual Studio code coverage results 153 | *.coverage 154 | *.coveragexml 155 | 156 | # NCrunch 157 | _NCrunch_* 158 | .*crunch*.local.xml 159 | nCrunchTemp_* 160 | 161 | # MightyMoose 162 | *.mm.* 163 | AutoTest.Net/ 164 | 165 | # Web workbench (sass) 166 | .sass-cache/ 167 | 168 | # Installshield output folder 169 | [Ee]xpress/ 170 | 171 | # DocProject is a documentation generator add-in 172 | DocProject/buildhelp/ 173 | DocProject/Help/*.HxT 174 | DocProject/Help/*.HxC 175 | DocProject/Help/*.hhc 176 | DocProject/Help/*.hhk 177 | DocProject/Help/*.hhp 178 | DocProject/Help/Html2 179 | DocProject/Help/html 180 | 181 | # Click-Once directory 182 | publish/ 183 | 184 | # Publish Web Output 185 | *.[Pp]ublish.xml 186 | *.azurePubxml 187 | # Note: Comment the next line if you want to checkin your web deploy settings, 188 | # but database connection strings (with potential passwords) will be unencrypted 189 | *.pubxml 190 | *.publishproj 191 | 192 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 193 | # checkin your Azure Web App publish settings, but sensitive information contained 194 | # in these scripts will be unencrypted 195 | PublishScripts/ 196 | 197 | # NuGet Packages 198 | *.nupkg 199 | # NuGet Symbol Packages 200 | *.snupkg 201 | # The packages folder can be ignored because of Package Restore 202 | **/[Pp]ackages/* 203 | # except build/, which is used as an MSBuild target. 204 | !**/[Pp]ackages/build/ 205 | # Uncomment if necessary however generally it will be regenerated when needed 206 | #!**/[Pp]ackages/repositories.config 207 | # NuGet v3's project.json files produces more ignorable files 208 | *.nuget.props 209 | *.nuget.targets 210 | 211 | # Microsoft Azure Build Output 212 | csx/ 213 | *.build.csdef 214 | 215 | # Microsoft Azure Emulator 216 | ecf/ 217 | rcf/ 218 | 219 | # Windows Store app package directories and files 220 | AppPackages/ 221 | BundleArtifacts/ 222 | Package.StoreAssociation.xml 223 | _pkginfo.txt 224 | *.appx 225 | *.appxbundle 226 | *.appxupload 227 | 228 | # Visual Studio cache files 229 | # files ending in .cache can be ignored 230 | *.[Cc]ache 231 | # but keep track of directories ending in .cache 232 | !?*.[Cc]ache/ 233 | 234 | # Others 235 | ClientBin/ 236 | ~$* 237 | *~ 238 | *.dbmdl 239 | *.dbproj.schemaview 240 | *.jfm 241 | *.pfx 242 | *.publishsettings 243 | orleans.codegen.cs 244 | 245 | # Including strong name files can present a security risk 246 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 247 | #*.snk 248 | 249 | # Since there are multiple workflows, uncomment next line to ignore bower_components 250 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 251 | #bower_components/ 252 | 253 | # RIA/Silverlight projects 254 | Generated_Code/ 255 | 256 | # Backup & report files from converting an old project file 257 | # to a newer Visual Studio version. Backup files are not needed, 258 | # because we have git ;-) 259 | _UpgradeReport_Files/ 260 | Backup*/ 261 | UpgradeLog*.XML 262 | UpgradeLog*.htm 263 | ServiceFabricBackup/ 264 | *.rptproj.bak 265 | 266 | # SQL Server files 267 | *.mdf 268 | *.ldf 269 | *.ndf 270 | 271 | # Business Intelligence projects 272 | *.rdl.data 273 | *.bim.layout 274 | *.bim_*.settings 275 | *.rptproj.rsuser 276 | *- [Bb]ackup.rdl 277 | *- [Bb]ackup ([0-9]).rdl 278 | *- [Bb]ackup ([0-9][0-9]).rdl 279 | 280 | # Microsoft Fakes 281 | FakesAssemblies/ 282 | 283 | # GhostDoc plugin setting file 284 | *.GhostDoc.xml 285 | 286 | # Node.js Tools for Visual Studio 287 | .ntvs_analysis.dat 288 | node_modules/ 289 | 290 | # Visual Studio 6 build log 291 | *.plg 292 | 293 | # Visual Studio 6 workspace options file 294 | *.opt 295 | 296 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 297 | *.vbw 298 | 299 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 300 | *.vbp 301 | 302 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 303 | *.dsw 304 | *.dsp 305 | 306 | # Visual Studio 6 technical files 307 | *.ncb 308 | *.aps 309 | 310 | # Visual Studio LightSwitch build output 311 | **/*.HTMLClient/GeneratedArtifacts 312 | **/*.DesktopClient/GeneratedArtifacts 313 | **/*.DesktopClient/ModelManifest.xml 314 | **/*.Server/GeneratedArtifacts 315 | **/*.Server/ModelManifest.xml 316 | _Pvt_Extensions 317 | 318 | # Paket dependency manager 319 | .paket/paket.exe 320 | paket-files/ 321 | 322 | # FAKE - F# Make 323 | .fake/ 324 | 325 | # CodeRush personal settings 326 | .cr/personal 327 | 328 | # Python Tools for Visual Studio (PTVS) 329 | __pycache__/ 330 | *.pyc 331 | 332 | # Cake - Uncomment if you are using it 333 | # tools/** 334 | # !tools/packages.config 335 | 336 | # Tabs Studio 337 | *.tss 338 | 339 | # Telerik's JustMock configuration file 340 | *.jmconfig 341 | 342 | # BizTalk build output 343 | *.btp.cs 344 | *.btm.cs 345 | *.odx.cs 346 | *.xsd.cs 347 | 348 | # OpenCover UI analysis results 349 | OpenCover/ 350 | 351 | # Azure Stream Analytics local run output 352 | ASALocalRun/ 353 | 354 | # MSBuild Binary and Structured Log 355 | *.binlog 356 | 357 | # NVidia Nsight GPU debugger configuration file 358 | *.nvuser 359 | 360 | # MFractors (Xamarin productivity tool) working folder 361 | .mfractor/ 362 | 363 | # Local History for Visual Studio 364 | .localhistory/ 365 | 366 | # Visual Studio History (VSHistory) files 367 | .vshistory/ 368 | 369 | # BeatPulse healthcheck temp database 370 | healthchecksdb 371 | 372 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 373 | MigrationBackup/ 374 | 375 | # Ionide (cross platform F# VS Code tools) working folder 376 | .ionide/ 377 | 378 | # Fody - auto-generated XML schema 379 | FodyWeavers.xsd 380 | 381 | # VS Code files for those working on multiple tools 382 | .vscode/* 383 | !.vscode/settings.json 384 | !.vscode/tasks.json 385 | !.vscode/launch.json 386 | !.vscode/extensions.json 387 | *.code-workspace 388 | 389 | # Local History for Visual Studio Code 390 | .history/ 391 | 392 | # Windows Installer files from build outputs 393 | *.cab 394 | *.msi 395 | *.msix 396 | *.msm 397 | *.msp 398 | 399 | # JetBrains Rider 400 | *.sln.iml 401 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.12.35728.132 d17.12 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebSvc", "WebSvc\WebSvc.csproj", "{9882C11A-5C01-4375-8B76-3CC4FC16E7CE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9882C11A-5C01-4375-8B76-3CC4FC16E7CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {9882C11A-5C01-4375-8B76-3CC4FC16E7CE}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {9882C11A-5C01-4375-8B76-3CC4FC16E7CE}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {9882C11A-5C01-4375-8B76-3CC4FC16E7CE}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/Controllers/MySvcController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Newtonsoft.Json.Linq; 3 | using Repositories; 4 | using Services; 5 | using System.Text.Json.Nodes; 6 | 7 | namespace Controllers 8 | { 9 | [ApiController] 10 | [Route("[controller]")] 11 | public class MySvcController : ControllerBase 12 | { 13 | 14 | private IDb _myDb = null; 15 | 16 | // Uncomment this to destroy everything!! 17 | public MySvcController(ISvcBuilder svcBuilder) 18 | { 19 | _myDb = svcBuilder.CreateDb(); 20 | } 21 | 22 | //public void SetDb(IDb db) 23 | //{ 24 | // _myDb = db; 25 | //} 26 | 27 | public MySvcController() 28 | { 29 | _myDb = ServiceBuilder.GetInstance().CreateDb(); 30 | } 31 | 32 | [HttpGet] 33 | public void Get([System.Web.Http.FromUri] int id, [System.Web.Http.FromUri] int age) 34 | { 35 | try 36 | { 37 | _myDb.UpdateBirth(id, age); 38 | } 39 | catch (Exception) 40 | { 41 | // Return Http code 400 42 | Response.StatusCode = 401; // This is wrong on purpose! 43 | return; 44 | } 45 | } 46 | 47 | [HttpPost] 48 | public void Post([System.Web.Http.FromUri] int id, [FromBody] object body) 49 | { 50 | IDictionary json = JObject.Parse(body.ToString()); 51 | 52 | bool ret = json.TryGetValue("age", out JToken val); 53 | 54 | int age = (int)val; 55 | try 56 | { 57 | _myDb.UpdateBirth(id, age); 58 | } 59 | catch (Exception) 60 | { 61 | Response.StatusCode = 400; 62 | return; 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | builder.Services.AddControllers(); 6 | 7 | var app = builder.Build(); 8 | 9 | // Configure the HTTP request pipeline. 10 | 11 | app.UseAuthorization(); 12 | 13 | app.MapControllers(); 14 | 15 | app.Run(); 16 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:45866", 8 | "sslPort": 0 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "MySvc", 17 | "applicationUrl": "http://localhost:5209", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "MySvc", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/Repositories/IDb.cs: -------------------------------------------------------------------------------- 1 | namespace Repositories 2 | { 3 | public interface IDb 4 | { 5 | void UpdateBirth(int key, int age); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/Repositories/InMemoryDb.cs: -------------------------------------------------------------------------------- 1 | namespace Repositories 2 | { 3 | public class InMemoryDb : IDb 4 | { 5 | public IDictionary _db = new Dictionary(); 6 | 7 | public InMemoryDb() 8 | { 9 | _db.Add(11, 25); 10 | } 11 | 12 | public void UpdateBirth(int key, int age) 13 | { 14 | if (!_db.ContainsKey(key)) 15 | throw new Exception("User with " + key + " does not exist!"); 16 | 17 | _db[key] = age; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/Repositories/MongoDB.cs: -------------------------------------------------------------------------------- 1 | namespace Repositories 2 | { 3 | public class MongoDB : IDb 4 | { 5 | public void UpdateBirth(int key, int age) 6 | { 7 | throw new NotImplementedException(); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/Services/IEnvironment.cs: -------------------------------------------------------------------------------- 1 | namespace Services 2 | { 3 | public interface IEnvironment 4 | { 5 | bool IsLocal(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/Services/ISvcBuilder.cs: -------------------------------------------------------------------------------- 1 | using Repositories; 2 | 3 | namespace Services 4 | { 5 | public interface ISvcBuilder 6 | { 7 | IDb CreateDb(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/Services/ServiceBuilder.cs: -------------------------------------------------------------------------------- 1 | using Repositories; 2 | 3 | namespace Services 4 | { 5 | public class ServiceBuilder : ISvcBuilder 6 | { 7 | private static ServiceBuilder _instance; 8 | private IEnvironment _env; 9 | 10 | public ServiceBuilder() 11 | { 12 | // TODO we will see how this is handled by a MW... 13 | this._env = new TheEnvironment(); 14 | } 15 | 16 | public static ISvcBuilder GetInstance() 17 | { 18 | if (_instance == null) 19 | _instance = new ServiceBuilder(); 20 | 21 | return _instance; 22 | } 23 | 24 | public IDb CreateDb() 25 | { 26 | if (_env.IsLocal()) 27 | return new InMemoryDb(); 28 | return new MongoDB(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/Services/TheEnvironment.cs: -------------------------------------------------------------------------------- 1 | namespace Services 2 | { 3 | public class TheEnvironment : IEnvironment 4 | { 5 | public bool IsLocal() 6 | { 7 | // TODO Read this by configuration file... 8 | return true; 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/UnitTests/MockThatThrowsException.cs: -------------------------------------------------------------------------------- 1 | using Repositories; 2 | 3 | namespace UnitTests 4 | { 5 | public class MockThatThrowsException : IDb 6 | { 7 | public MockThatThrowsException() : base() 8 | { } 9 | 10 | public void UpdateBirth(int key, int age) 11 | { 12 | throw new Exception("User with " + key + " does not exist!"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/UnitTests/MyControllerTest.cs: -------------------------------------------------------------------------------- 1 | using Controllers; 2 | 3 | namespace UnitTests 4 | { 5 | public class MyControllerTest 6 | { 7 | private static void Assert(T expected, T actual) where T: class 8 | { 9 | if (expected != actual) 10 | { 11 | Console.WriteLine("Assertion failed! Expected " + expected + ", got " + actual + " instead"); 12 | Environment.Exit(-1); 13 | } 14 | } 15 | 16 | private static void MyServlet_DbThrowsException_Return400() 17 | { 18 | // Arrange 19 | 20 | // Mock svcbuilder 21 | //ServicesBuilderForMocks svcBuilder = new ServicesBuilderForMocks(); 22 | 23 | // Mock up HttpServletRequest and HttpServletResponse 24 | //MyHttpServletRequest request = new MyHttpServletRequest(); 25 | //request.setParameter("id", "1"); // This causes an exception 26 | //request.setParameter("age", "34"); 27 | //MyHttpServletResponse response = new MyHttpServletResponse(); 28 | 29 | // SUT stands for "Service Under Test" 30 | MySvcController sut = new MySvcController(); 31 | //sut.SetDb(new MockThatThrowsException()); 32 | 33 | // Act 34 | 35 | Exception ex = null; 36 | 37 | try 38 | { 39 | sut.Get(11, 43); 40 | } 41 | catch (Exception e) 42 | { 43 | ex = e; 44 | } 45 | 46 | // Assert 47 | 48 | Assert(ex, null); 49 | //Assert(response.getStatus(), 400); 50 | } 51 | 52 | //public static void Main(string[] args) 53 | //{ 54 | // MyServlet_DbThrowsException_Return400(); 55 | //} 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/UnitTests/ServicesBuilderForMocks.cs: -------------------------------------------------------------------------------- 1 | using Repositories; 2 | using Services; 3 | 4 | namespace UnitTests 5 | { 6 | public class ServicesBuilderForMocks : ISvcBuilder 7 | { 8 | public IDb CreateDb() 9 | { 10 | return new MockThatThrowsException(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/WebSvc.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/WebSvc.http: -------------------------------------------------------------------------------- 1 | @WebSvc_HostAddress = http://localhost:5209 2 | 3 | GET {{WebSvc_HostAddress}}/MySvc/ 4 | Accept: application/json 5 | 6 | ### 7 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Code/WebSvc/WebSvc/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /Code/dotNetBasics/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | # but not Directory.Build.rsp, as it configures directory-level build defaults 86 | !Directory.Build.rsp 87 | *.sbr 88 | *.tlb 89 | *.tli 90 | *.tlh 91 | *.tmp 92 | *.tmp_proj 93 | *_wpftmp.csproj 94 | *.log 95 | *.tlog 96 | *.vspscc 97 | *.vssscc 98 | .builds 99 | *.pidb 100 | *.svclog 101 | *.scc 102 | 103 | # Chutzpah Test files 104 | _Chutzpah* 105 | 106 | # Visual C++ cache files 107 | ipch/ 108 | *.aps 109 | *.ncb 110 | *.opendb 111 | *.opensdf 112 | *.sdf 113 | *.cachefile 114 | *.VC.db 115 | *.VC.VC.opendb 116 | 117 | # Visual Studio profiler 118 | *.psess 119 | *.vsp 120 | *.vspx 121 | *.sap 122 | 123 | # Visual Studio Trace Files 124 | *.e2e 125 | 126 | # TFS 2012 Local Workspace 127 | $tf/ 128 | 129 | # Guidance Automation Toolkit 130 | *.gpState 131 | 132 | # ReSharper is a .NET coding add-in 133 | _ReSharper*/ 134 | *.[Rr]e[Ss]harper 135 | *.DotSettings.user 136 | 137 | # TeamCity is a build add-in 138 | _TeamCity* 139 | 140 | # DotCover is a Code Coverage Tool 141 | *.dotCover 142 | 143 | # AxoCover is a Code Coverage Tool 144 | .axoCover/* 145 | !.axoCover/settings.json 146 | 147 | # Coverlet is a free, cross platform Code Coverage Tool 148 | coverage*.json 149 | coverage*.xml 150 | coverage*.info 151 | 152 | # Visual Studio code coverage results 153 | *.coverage 154 | *.coveragexml 155 | 156 | # NCrunch 157 | _NCrunch_* 158 | .*crunch*.local.xml 159 | nCrunchTemp_* 160 | 161 | # MightyMoose 162 | *.mm.* 163 | AutoTest.Net/ 164 | 165 | # Web workbench (sass) 166 | .sass-cache/ 167 | 168 | # Installshield output folder 169 | [Ee]xpress/ 170 | 171 | # DocProject is a documentation generator add-in 172 | DocProject/buildhelp/ 173 | DocProject/Help/*.HxT 174 | DocProject/Help/*.HxC 175 | DocProject/Help/*.hhc 176 | DocProject/Help/*.hhk 177 | DocProject/Help/*.hhp 178 | DocProject/Help/Html2 179 | DocProject/Help/html 180 | 181 | # Click-Once directory 182 | publish/ 183 | 184 | # Publish Web Output 185 | *.[Pp]ublish.xml 186 | *.azurePubxml 187 | # Note: Comment the next line if you want to checkin your web deploy settings, 188 | # but database connection strings (with potential passwords) will be unencrypted 189 | *.pubxml 190 | *.publishproj 191 | 192 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 193 | # checkin your Azure Web App publish settings, but sensitive information contained 194 | # in these scripts will be unencrypted 195 | PublishScripts/ 196 | 197 | # NuGet Packages 198 | *.nupkg 199 | # NuGet Symbol Packages 200 | *.snupkg 201 | # The packages folder can be ignored because of Package Restore 202 | **/[Pp]ackages/* 203 | # except build/, which is used as an MSBuild target. 204 | !**/[Pp]ackages/build/ 205 | # Uncomment if necessary however generally it will be regenerated when needed 206 | #!**/[Pp]ackages/repositories.config 207 | # NuGet v3's project.json files produces more ignorable files 208 | *.nuget.props 209 | *.nuget.targets 210 | 211 | # Microsoft Azure Build Output 212 | csx/ 213 | *.build.csdef 214 | 215 | # Microsoft Azure Emulator 216 | ecf/ 217 | rcf/ 218 | 219 | # Windows Store app package directories and files 220 | AppPackages/ 221 | BundleArtifacts/ 222 | Package.StoreAssociation.xml 223 | _pkginfo.txt 224 | *.appx 225 | *.appxbundle 226 | *.appxupload 227 | 228 | # Visual Studio cache files 229 | # files ending in .cache can be ignored 230 | *.[Cc]ache 231 | # but keep track of directories ending in .cache 232 | !?*.[Cc]ache/ 233 | 234 | # Others 235 | ClientBin/ 236 | ~$* 237 | *~ 238 | *.dbmdl 239 | *.dbproj.schemaview 240 | *.jfm 241 | *.pfx 242 | *.publishsettings 243 | orleans.codegen.cs 244 | 245 | # Including strong name files can present a security risk 246 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 247 | #*.snk 248 | 249 | # Since there are multiple workflows, uncomment next line to ignore bower_components 250 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 251 | #bower_components/ 252 | 253 | # RIA/Silverlight projects 254 | Generated_Code/ 255 | 256 | # Backup & report files from converting an old project file 257 | # to a newer Visual Studio version. Backup files are not needed, 258 | # because we have git ;-) 259 | _UpgradeReport_Files/ 260 | Backup*/ 261 | UpgradeLog*.XML 262 | UpgradeLog*.htm 263 | ServiceFabricBackup/ 264 | *.rptproj.bak 265 | 266 | # SQL Server files 267 | *.mdf 268 | *.ldf 269 | *.ndf 270 | 271 | # Business Intelligence projects 272 | *.rdl.data 273 | *.bim.layout 274 | *.bim_*.settings 275 | *.rptproj.rsuser 276 | *- [Bb]ackup.rdl 277 | *- [Bb]ackup ([0-9]).rdl 278 | *- [Bb]ackup ([0-9][0-9]).rdl 279 | 280 | # Microsoft Fakes 281 | FakesAssemblies/ 282 | 283 | # GhostDoc plugin setting file 284 | *.GhostDoc.xml 285 | 286 | # Node.js Tools for Visual Studio 287 | .ntvs_analysis.dat 288 | node_modules/ 289 | 290 | # Visual Studio 6 build log 291 | *.plg 292 | 293 | # Visual Studio 6 workspace options file 294 | *.opt 295 | 296 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 297 | *.vbw 298 | 299 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 300 | *.vbp 301 | 302 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 303 | *.dsw 304 | *.dsp 305 | 306 | # Visual Studio 6 technical files 307 | *.ncb 308 | *.aps 309 | 310 | # Visual Studio LightSwitch build output 311 | **/*.HTMLClient/GeneratedArtifacts 312 | **/*.DesktopClient/GeneratedArtifacts 313 | **/*.DesktopClient/ModelManifest.xml 314 | **/*.Server/GeneratedArtifacts 315 | **/*.Server/ModelManifest.xml 316 | _Pvt_Extensions 317 | 318 | # Paket dependency manager 319 | .paket/paket.exe 320 | paket-files/ 321 | 322 | # FAKE - F# Make 323 | .fake/ 324 | 325 | # CodeRush personal settings 326 | .cr/personal 327 | 328 | # Python Tools for Visual Studio (PTVS) 329 | __pycache__/ 330 | *.pyc 331 | 332 | # Cake - Uncomment if you are using it 333 | # tools/** 334 | # !tools/packages.config 335 | 336 | # Tabs Studio 337 | *.tss 338 | 339 | # Telerik's JustMock configuration file 340 | *.jmconfig 341 | 342 | # BizTalk build output 343 | *.btp.cs 344 | *.btm.cs 345 | *.odx.cs 346 | *.xsd.cs 347 | 348 | # OpenCover UI analysis results 349 | OpenCover/ 350 | 351 | # Azure Stream Analytics local run output 352 | ASALocalRun/ 353 | 354 | # MSBuild Binary and Structured Log 355 | *.binlog 356 | 357 | # NVidia Nsight GPU debugger configuration file 358 | *.nvuser 359 | 360 | # MFractors (Xamarin productivity tool) working folder 361 | .mfractor/ 362 | 363 | # Local History for Visual Studio 364 | .localhistory/ 365 | 366 | # Visual Studio History (VSHistory) files 367 | .vshistory/ 368 | 369 | # BeatPulse healthcheck temp database 370 | healthchecksdb 371 | 372 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 373 | MigrationBackup/ 374 | 375 | # Ionide (cross platform F# VS Code tools) working folder 376 | .ionide/ 377 | 378 | # Fody - auto-generated XML schema 379 | FodyWeavers.xsd 380 | 381 | # VS Code files for those working on multiple tools 382 | .vscode/* 383 | !.vscode/settings.json 384 | !.vscode/tasks.json 385 | !.vscode/launch.json 386 | !.vscode/extensions.json 387 | *.code-workspace 388 | 389 | # Local History for Visual Studio Code 390 | .history/ 391 | 392 | # Windows Installer files from build outputs 393 | *.cab 394 | *.msi 395 | *.msix 396 | *.msm 397 | *.msp 398 | 399 | # JetBrains Rider 400 | *.sln.iml 401 | -------------------------------------------------------------------------------- /Code/dotNetBasics/ConsoleApp/ConsoleApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Code/dotNetBasics/ConsoleApp/IMyList.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleApp 2 | { 3 | internal interface IMyList 4 | { 5 | IMyList Add(int i); 6 | 7 | IMyList Reorder(); 8 | 9 | IMyList Persist(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Code/dotNetBasics/ConsoleApp/MyDataType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ConsoleApp 8 | { 9 | internal class MyDataType 10 | { 11 | private int _id; 12 | private string _payload = ""; 13 | 14 | //public void SetId(int id) 15 | //{ 16 | // _id = id; 17 | //} 18 | 19 | //public int GetId() 20 | //{ 21 | // return _id; 22 | //} 23 | 24 | // Property that shadows the _id field 25 | public int Id 26 | { 27 | get 28 | { 29 | return _id; 30 | } 31 | set 32 | { 33 | _id = value; 34 | } 35 | } 36 | 37 | // Properties with body expression 38 | //public string Payload => _payload; 39 | public string Payload 40 | { 41 | get 42 | { 43 | return _payload; 44 | } 45 | set 46 | { 47 | _payload = value; 48 | } 49 | } 50 | 51 | // Function with body expression 52 | public int MultiplydByFour() => _id * 4; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Code/dotNetBasics/ConsoleApp/MyList.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleApp 2 | { 3 | public enum MyListState 4 | { 5 | Draft = 0, 6 | Inserting, 7 | Ordered, 8 | Stored 9 | }; 10 | 11 | internal class MyList : IMyList 12 | { 13 | private List _thelist = new List(); 14 | private MyListState _state = MyListState.Draft; 15 | 16 | public MyListState State { get { return _state; } } 17 | 18 | public IMyList Add(int i) 19 | { 20 | _thelist.Add(i); 21 | _state = MyListState.Inserting; 22 | return this; 23 | } 24 | 25 | public IMyList Reorder() 26 | { 27 | _thelist.Sort(); 28 | _state = MyListState.Ordered; 29 | return this; 30 | } 31 | 32 | public IMyList Persist() 33 | { 34 | // File.WriteAllLines requires a "IEnumerable" param. 35 | // We could do this using the "usual way".... 36 | 37 | //var listAsString = new List(); 38 | //foreach (int i in _thelist) 39 | // listAsString.Add(i.ToString() + Environment.NewLine); 40 | 41 | //File.WriteAllLines("file.txt", listAsString); 42 | 43 | // ...but it's faster using fluent Linq API 44 | File.WriteAllLines("file.txt", _thelist.Select(x => x.ToString())); 45 | 46 | _state = MyListState.Stored; 47 | return this; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Code/dotNetBasics/ConsoleApp/MyModel.cs: -------------------------------------------------------------------------------- 1 | namespace ConsoleApp 2 | { 3 | internal class MyModel 4 | { 5 | int mydata = 4; 6 | public void Invoke(Action fn) 7 | { 8 | fn(mydata); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Code/dotNetBasics/ConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using ConsoleApp; 2 | 3 | internal class Program 4 | { 5 | /// 6 | /// Main entry point of application (class-based implementation). Could also be "script-like", main free implementation. 7 | /// 8 | /// 9 | private static void Main(string[] args) 10 | { 11 | // 12 | // 1. Referencing classes from another projects 13 | // 14 | 15 | MySharedProject.MyClass myObj = new MySharedProject.MyClass(); 16 | MyClassLibrary.MyClass myObj2 = new MyClassLibrary.MyClass(); 17 | 18 | int multiplyRes = myObj.MultiplyByTwo(11); 19 | int divideRes = myObj2.DivideByTwo(4); 20 | 21 | Console.WriteLine($" Results are {multiplyRes} - {divideRes}" ); 22 | 23 | // 24 | // 2. Vars in nested context 25 | int b; 26 | for(int i = 0; i < 50; i++) 27 | { 28 | // This won't compile! 29 | //int a; 30 | } 31 | 32 | 33 | // 34 | // 3. Checked/unchecked 35 | // 36 | uint a = uint.MaxValue; 37 | 38 | unchecked 39 | { 40 | Console.WriteLine(a + 3); // output: 2 41 | } 42 | 43 | try 44 | { 45 | checked 46 | { 47 | Console.WriteLine(a + 3); 48 | } 49 | } 50 | catch (OverflowException e) 51 | { 52 | Console.WriteLine(e.Message); // output: Arithmetic operation resulted in an overflow. 53 | } 54 | 55 | 56 | // 57 | // 4. Lambda fns 58 | // 59 | Action myLambda = (int a) => 60 | { 61 | Console.WriteLine($"a is {a}"); 62 | }; 63 | 64 | // Call it directly... 65 | myLambda(4); 66 | 67 | // ...or implement a Visitor pattern 68 | var dataowner = new MyModel(); 69 | dataowner.Invoke(myLambda); 70 | 71 | 72 | // 73 | // 5. Fluent interface 74 | // 75 | var myfluentlist = new MyList(); 76 | myfluentlist.Add(5) 77 | .Add(1) 78 | .Add(5652) 79 | //.Reorder() 80 | .Persist(); 81 | 82 | Console.WriteLine($"List is in state {myfluentlist.State}"); 83 | 84 | // 85 | // 6. Use of list and linq-to-sql 86 | // 87 | 88 | var mylist = new List() 89 | { 90 | new MyDataType() { Id = 0, Payload = "Paolo" }, 91 | new MyDataType() { Id = 1, Payload = "Cristina" }, 92 | new MyDataType() { Id = 2, Payload = "Andrea" }, 93 | new MyDataType() { Id = 3, Payload = "Benedetta" }, 94 | new MyDataType() { Id = 5, Payload = "Angelo" }, 95 | }; 96 | 97 | // SQL syntax 98 | 99 | IEnumerable result = from i in mylist 100 | where i.Payload.StartsWith("A") 101 | select i.Id; 102 | 103 | // Fluent interface 104 | var result2 = mylist.Where(i => i.Payload.StartsWith("A")) 105 | .Select(j => j.Id); 106 | 107 | Console.WriteLine($"Found object at Id {result.FirstOrDefault()}"); 108 | } 109 | } -------------------------------------------------------------------------------- /Code/dotNetBasics/ConsoleApp/README.md: -------------------------------------------------------------------------------- 1 | # ConsoleApp 2 | 3 | A simple Console application to show some basic features of dotNet. -------------------------------------------------------------------------------- /Code/dotNetBasics/MyClassLibrary/MyClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MyClassLibrary 4 | { 5 | /// 6 | /// /This class implements the business functionality 7 | /// 8 | public class MyClass 9 | { 10 | /// 11 | /// Divide an integer by two. If the number is negative or equal to zero, 12 | /// throw an 13 | /// 14 | /// 15 | /// 16 | public int DivideByTwo(int a) 17 | { 18 | if (a <= 0) throw new ArgumentException($"Inut number cannot be <=0, i.e., {a}"); 19 | return a / 2; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Code/dotNetBasics/MyClassLibrary/MyClassLibrary.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {A41DE25E-2117-48CD-A0CC-9750910B5458} 8 | Library 9 | Properties 10 | MyClassLibrary 11 | MyClassLibrary 12 | v4.7.2 13 | 512 14 | true 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Code/dotNetBasics/MyClassLibrary/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("MyClassLibrary")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MyClassLibrary")] 13 | [assembly: AssemblyCopyright("Copyright © 2025")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a41de25e-2117-48cd-a0cc-9750910b5458")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | -------------------------------------------------------------------------------- /Code/dotNetBasics/MyClassLibrary/README.md: -------------------------------------------------------------------------------- 1 | # MyClassLibrary 2 | 3 | This project implements a functionality that has to be published as a DLL. 4 | 5 | It exposes a single method that divides an integer number by two, and throws an `ArgumentException`. -------------------------------------------------------------------------------- /Code/dotNetBasics/MySharedProject/MyClass.cs: -------------------------------------------------------------------------------- 1 | namespace MySharedProject 2 | { 3 | /// 4 | /// /This class implements the business functionality 5 | /// 6 | public class MyClass 7 | { 8 | /// 9 | /// Multiply an integer by two. 10 | /// 11 | /// 12 | /// 13 | public int MultiplyByTwo(int a) 14 | { 15 | return a * 2; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Code/dotNetBasics/MySharedProject/MySharedProject.projitems: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | 72b337bb-ab4a-4348-92fc-f0b061cf7b7e 7 | 8 | 9 | MySharedProject 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Code/dotNetBasics/MySharedProject/MySharedProject.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 72b337bb-ab4a-4348-92fc-f0b061cf7b7e 5 | 14.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Code/dotNetBasics/MySharedProject/README.md: -------------------------------------------------------------------------------- 1 | # MySharedProject 2 | 3 | Shared projects are simple containers of code, which will be included in the Assembly of other referencing projects. 4 | Their functionality can't be published as standalone. 5 | 6 | It exposes a single method that multiplies an integer number by two. -------------------------------------------------------------------------------- /Code/dotNetBasics/UnitTests/MyClassLibraryUnitTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using MyClassLibrary; 3 | using System; 4 | 5 | namespace UnitTests 6 | { 7 | /// 8 | /// Unit tests for MyClassLibrary 9 | /// 10 | [TestClass] 11 | public class MyClassLibraryUnitTest 12 | { 13 | [TestMethod] 14 | public void DivideByTwo_NegativeInput_ThrowsException() 15 | { 16 | // Arrange 17 | MyClass sut = new MyClass(); 18 | Exception ex = null; 19 | 20 | // Act 21 | try 22 | { 23 | sut.DivideByTwo(-1); 24 | } 25 | catch (ArgumentException e) 26 | { 27 | ex = e; 28 | } 29 | 30 | // Assert 31 | Assert.IsNotNull(ex); 32 | Assert.IsInstanceOfType(ex, typeof(ArgumentException)); 33 | } 34 | 35 | /// 36 | /// Second version of the same test as before, which uses Attributes to specify the expected result 37 | /// 38 | [TestMethod] 39 | [ExpectedException(typeof(ArgumentException), "An ArgumentException was expected")] 40 | public void DivideByTwo_NegativeInput_ThrowsException_2() 41 | { 42 | // Arrange 43 | MyClass sut = new MyClass(); 44 | 45 | // Act 46 | sut.DivideByTwo(-1); 47 | 48 | // Assert 49 | // Really nothing to do, here... 50 | } 51 | 52 | /// 53 | /// Correct functionality (even nr). 54 | /// 55 | [TestMethod] 56 | public void DivideByTwo_PositiveInput_CorrectResult() 57 | { 58 | // Arrange 59 | MyClass sut = new MyClass(); 60 | int testVal = 14; 61 | 62 | // Act 63 | var retval = sut.DivideByTwo(testVal); 64 | 65 | 66 | // Assert 67 | Assert.AreEqual(testVal / 2, retval); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Code/dotNetBasics/UnitTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("UnitTests")] 6 | [assembly: AssemblyDescription("")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany("")] 9 | [assembly: AssemblyProduct("UnitTests")] 10 | [assembly: AssemblyCopyright("Copyright © 2025")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: Guid("b84acea5-0e41-4f92-9c6b-1087d2c74031")] 17 | 18 | // [assembly: AssemblyVersion("1.0.*")] 19 | [assembly: AssemblyVersion("1.0.0.0")] 20 | [assembly: AssemblyFileVersion("1.0.0.0")] 21 | -------------------------------------------------------------------------------- /Code/dotNetBasics/UnitTests/README.md: -------------------------------------------------------------------------------- 1 | # UnitTests 2 | 3 | These are the unit tests. They use dotNet toolkit for tesitng (see project references). -------------------------------------------------------------------------------- /Code/dotNetBasics/UnitTests/UnitTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {B84ACEA5-0E41-4F92-9C6B-1087D2C74031} 9 | Library 10 | Properties 11 | UnitTests 12 | UnitTests 13 | v4.7.2 14 | 512 15 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 16 | 15.0 17 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 18 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 19 | False 20 | UnitTest 21 | 22 | 23 | 24 | 25 | true 26 | full 27 | false 28 | bin\Debug\ 29 | DEBUG;TRACE 30 | prompt 31 | 4 32 | 33 | 34 | pdbonly 35 | true 36 | bin\Release\ 37 | TRACE 38 | prompt 39 | 4 40 | 41 | 42 | 43 | ..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll 44 | 45 | 46 | ..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | {a41de25e-2117-48cd-a0cc-9750910b5458} 62 | MyClassLibrary 63 | 64 | 65 | 66 | 67 | 68 | 69 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /Code/dotNetBasics/UnitTests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Code/dotNetBasics/dotNetBasics.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.12.35728.132 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{FF00C210-A09C-4109-B417-37EDF4F3B413}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyClassLibrary", "MyClassLibrary\MyClassLibrary.csproj", "{A41DE25E-2117-48CD-A0CC-9750910B5458}" 9 | EndProject 10 | Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "MySharedProject", "MySharedProject\MySharedProject.shproj", "{72B337BB-AB4A-4348-92FC-F0B061CF7B7E}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{B84ACEA5-0E41-4F92-9C6B-1087D2C74031}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {FF00C210-A09C-4109-B417-37EDF4F3B413}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {FF00C210-A09C-4109-B417-37EDF4F3B413}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {FF00C210-A09C-4109-B417-37EDF4F3B413}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {FF00C210-A09C-4109-B417-37EDF4F3B413}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {A41DE25E-2117-48CD-A0CC-9750910B5458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {A41DE25E-2117-48CD-A0CC-9750910B5458}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {A41DE25E-2117-48CD-A0CC-9750910B5458}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {A41DE25E-2117-48CD-A0CC-9750910B5458}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {B84ACEA5-0E41-4F92-9C6B-1087D2C74031}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {B84ACEA5-0E41-4F92-9C6B-1087D2C74031}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {B84ACEA5-0E41-4F92-9C6B-1087D2C74031}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {B84ACEA5-0E41-4F92-9C6B-1087D2C74031}.Release|Any CPU.Build.0 = Release|Any CPU 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | GlobalSection(SharedMSBuildProjectFiles) = preSolution 37 | MySharedProject\MySharedProject.projitems*{72b337bb-ab4a-4348-92fc-f0b061cf7b7e}*SharedItemsImports = 13 38 | MySharedProject\MySharedProject.projitems*{ff00c210-a09c-4109-b417-37edf4f3b413}*SharedItemsImports = 5 39 | EndGlobalSection 40 | EndGlobal 41 | -------------------------------------------------------------------------------- /Exams/20240607 Scritto - Soluzione.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Exams/20240607 Scritto - Soluzione.pdf -------------------------------------------------------------------------------- /Exams/20240607 Scritto.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Exams/20240607 Scritto.pdf -------------------------------------------------------------------------------- /Exams/20240708 Scritto - Soluzione.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Exams/20240708 Scritto - Soluzione.pdf -------------------------------------------------------------------------------- /Exams/20240708 Scritto.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Exams/20240708 Scritto.pdf -------------------------------------------------------------------------------- /FAQ.md: -------------------------------------------------------------------------------- 1 | # Progetto del software LT - FAQ 2 | 3 | #### A che condizioni si supera l’esame? E’ obbligatorio fare l’orale? 4 | 5 | No, non è obbligatorio fare l’orale. Se nel test scritto si raggiungono almeno 9 punti nelle domande a crocette, e almeno 15 in totale, si può registrare il voto. Va da sé che in tal caso è necessario sostenere un orale per raggiungere almeno la sufficienza di 18 punti. 6 | 7 | 8 | #### Cosa mi serve per seguire le lezioni? 9 | 10 | Innanzitutto, direi queste slide. I libri non sono obbligatori, ma contengono comunque i concetti espressi nelle slide, e in piu' alcuni approfondimenti utili. 11 | Sara' necessario un computer per svolgere le esercitazioni, e una (o piu') delle board embedded segnalate nelle slide. 12 | Qualora il candidato non potesse/volesse comprarne una, puo' rivolgersi al docente per trovare una soluzione. 13 | 14 | 15 | #### Non ho ottenuto le propedeuticità. Posso lo stesso effettuare l’esame? 16 | 17 | Non ci sono propedeuticità, se non un minimo di esperienza di programmazione C/C++, preferibilmente in ambiente GNU/Linux 18 | 19 | #### Cosa succede se vengo “beccato” a parlare o a copiare all’esame? 20 | 21 | Espulsione diretta dall’aula, senza se e senza ma, a insindacabile giudizio del docente, più eventualmente con salto dell’intera sessione successiva, per casi gravi. 22 | 23 | Non dite che non ve l’avevo detto. 24 | 25 | #### Non sono riuscito a restare alla correzione, il mio compito è ancora valido? 26 | 27 | Il compito è ancora valido, ma non è stato corretto, e “vale” un anno. Si prega di contattare i docenti per procedere alla correzione, e ottenere un voto registrabile. 28 | 29 | #### Quanto rimane valido un voto? 30 | 31 | I voti della prova scritta durano un anno. Qualora lo studente partecipasse alla correzione di una prova scritta successiva, perderebbe il voto precedentemente acquisito. Se uno studente chiede la prova orale, il voto conseguito dura fino alla fine della sessione corrente. 32 | 33 | Il voto conseguito dopo la prova orale rimane valido fino a una settimana dopo l’ultimo appello scritto della sessione (o dell’orale equivalente). Dopodiché, o si richiede esplicitamente che venga registrato, o il voto è perso, e il candidato deve rifare lo scritto. 34 | 35 | #### Dopo la correzione, non sono soddisfatto del voto che ho ottenuto allo scritto. Posso eventualmente riprovare il compito senza perdere il voto? 36 | 37 | Sì. Qualora tuttavia il candidato consegnasse e partecipasse alla correzione del secondo tentativo, perderebbe il voto precedentemente acquisito. 38 | 39 | #### Quando posso registrare un voto? 40 | 41 | Qualora lo studente accettasse un voto, esso verrà registrato una settimana dopo l’ultimo appello scritto della sessione, o dell’orale equivalente. Eventuali urgenze (tirocini, tesi ecc ecc) verranno soddisfatte appena possibile. 42 | 43 | #### Come posso fare per avere la lode? 44 | 45 | La lode è possibile solo attraverso l’esame orale, o il progetto 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | HiPeRT logo 3 | 4 | 5 | # Progetto del software LT - 2024/25 6 |

7 | This is official repository of the course of Software design LT, Year 2024/25, at University of Modena and Reggio Emilia, held at Department of Physics, Informatics and Mathematics (FIM) 8 | 9 | Course page | FAQ | How to use Git to work with this repo 10 | | Drive folder with shared material 11 | 12 |

13 | 14 | ## Folder structure 15 | 16 | - Code/ --> Code snippets & tutorials 17 | - Exams/ --> Past exams (with solutions) 18 | - Seminars/ --> Meet the companies 19 | - Slides/ --> Course slides 20 | -------------------------------------------------------------------------------- /Seminars/La tutela del software aspetti tecnici e legali.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Seminars/La tutela del software aspetti tecnici e legali.pdf -------------------------------------------------------------------------------- /Slides/00 - Course Introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/00 - Course Introduction.pdf -------------------------------------------------------------------------------- /Slides/01 - Collaborative tools.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/01 - Collaborative tools.pdf -------------------------------------------------------------------------------- /Slides/02 - The software design process.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/02 - The software design process.pdf -------------------------------------------------------------------------------- /Slides/03 - Requirements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/03 - Requirements.pdf -------------------------------------------------------------------------------- /Slides/04 - Documentation - Notation and tools.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/04 - Documentation - Notation and tools.pdf -------------------------------------------------------------------------------- /Slides/05 - Unified Modeling Language.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/05 - Unified Modeling Language.pdf -------------------------------------------------------------------------------- /Slides/06 - System design.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/06 - System design.pdf -------------------------------------------------------------------------------- /Slides/07 - UML and OOP.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/07 - UML and OOP.pdf -------------------------------------------------------------------------------- /Slides/08 - Solid.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/08 - Solid.pdf -------------------------------------------------------------------------------- /Slides/09 - Design patterns.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/09 - Design patterns.pdf -------------------------------------------------------------------------------- /Slides/10 - CLEAN code architecture.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/10 - CLEAN code architecture.pdf -------------------------------------------------------------------------------- /Slides/11 - dotNet and CSharp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/11 - dotNet and CSharp.pdf -------------------------------------------------------------------------------- /Slides/Precariato universitario.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HiPeRT/ProgSW/ff7fde5587141c09a1e032f03a00be257a8de6c1/Slides/Precariato universitario.pdf --------------------------------------------------------------------------------